Skip to content
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

Library incompatible with NativeStackNavigator from React Navigation (crashes app) #61

Open
goguda opened this issue Aug 4, 2021 · 3 comments

Comments

@goguda
Copy link

goguda commented Aug 4, 2021

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

skeleton-bug.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?

@chramos
Copy link
Owner

chramos commented Dec 8, 2021

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

@KostasPik
Copy link

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

@warapolj
Copy link

    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 />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants