react-native-skeleton-placeholder icon indicating copy to clipboard operation
react-native-skeleton-placeholder copied to clipboard

Library incompatible with NativeStackNavigator from React Navigation (crashes app)

Open goguda opened this issue 4 years ago • 3 comments

This library causes the whole app to crash on navigation pop() method when using the Native Stack Navigator from React Navigation:

https://user-images.githubusercontent.com/26887502/128106305-ffbfe955-1c22-4588-badb-2414b179dc23.mp4

I believe this is caused by the skeleton trying to update its state even after the parent component has been unmounted. To fix this, I believe a this.isMounted style check needs to be done within the component itself before updating its own state.

I'm mostly used to class-based React since this project has gotten so big and complex; I know that in class-based React, this would be accomplished by setting this.isMounted = true in componentDidMount() and this.isMounted = false in componentWillUnmount(), and wrapping any this.setState() calls like if (this.isMounted) {this.setState()}.

I wouldn't be the most comfortable implementing this with hooks like this library uses, perhaps someone can provide some insight on how this can be done with hooks and integrated into the library?

goguda avatar Aug 04 '21 01:08 goguda

@goguda the issue happens only with pop()? what's about goBack()?

chramos avatar Dec 08 '21 12:12 chramos

Has this issue been solved? I have the exact same issue with react navigation.

KostasPik avatar Oct 16 '22 12:10 KostasPik


    const [requestGoBack, setRequestGoBack] = useState(false)
    const navigation = useNavigation()

    useEffect(() => {
      return navigation.addListener('beforeRemove', (e) => {
        e.preventDefault()
        setRequestGoBack(true)
        setTimeout(() => {
          navigation.dispatch(e.data.action)
        }, 250)
      })
    }, [navigation])

    if (requestGoBack) {
      return <></>
    }

    return <Component />

warapolj avatar Jul 10 '23 13:07 warapolj