-
-
Notifications
You must be signed in to change notification settings - Fork 780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: backdrop -> check if mounted before setting state #1657
Conversation
i tried to repo the issue but i couldn't, do you have a repo example ? |
@gorhom I don't have a repo example but I just used this component: BottomSheet.tsx componentimport {
BottomSheetBackdrop,
BottomSheetBackdropProps,
BottomSheetModal,
BottomSheetScrollView,
} from '@gorhom/bottom-sheet';
import React, {useCallback, useRef} from 'react';
import {Button, Text, View} from 'react-native';
interface Props {}
export const BottomSheet = ({}: Props) => {
const bottomSheetModalRef = useRef<BottomSheetModal>(null);
const backdropComponent = useCallback(
(props: BottomSheetBackdropProps) => (
<BottomSheetBackdrop
{...props}
appearsOnIndex={0}
disappearsOnIndex={-1}
/>
),
[],
);
return (
<View>
<Button
title="Open Bottom Sheet"
onPress={() => {
bottomSheetModalRef.current?.present();
}}
/>
<BottomSheetModal
ref={bottomSheetModalRef}
snapPoints={['25%']}
backdropComponent={backdropComponent}>
<BottomSheetScrollView>
<>
<Text>1 Lorem Ipsum</Text>
<Text>2 Lorem Ipsum</Text>
</>
</BottomSheetScrollView>
</BottomSheetModal>
</View>
);
}; I'm using
bottom-sheet-unmount-update.mov |
@@ -53,6 +61,16 @@ const BottomSheetBackdropComponent = ({ | |||
>(enableTouchThrough ? 'none' : 'auto'); | |||
//#endregion | |||
|
|||
//#region effects | |||
useEffect(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you move this hook to the region at the end effects
looks good, i just left a code styling comment, once it is addressed im going to merge this PR into |
Thank you for merging |
closes #1376 (has already been closed, although it hasn't been fixed yet )
Motivation
When using the backdrop component you could get a
"Warning: Can't perform a React state update on an unmounted component [...] in BottomSheetBackdrop"
error.This PR adds a check if the component is mounted before setting the local state to fix that issue.