Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

navigation.dangerouslyGetParent is not a function How can i fix this problem?

i am facing a error callednavigation.dangerouslyGetParent is not a function and its undefined so how can i fix this issue? what can i write in place of dangerouslyGetParent() if its not a function?

` useEffect(() => {
        const unsubscribe = navigation.dangerouslyGetParent().addListener('tabPress', e => {
            console.log("TAB PRESSED");
            if(refPosts.current){
                refPosts.current.scrollToIndex({ animated: true, index: 0 });
            }
        });`

1 Answers

https://reactnavigation.org/docs/upgrading-from-5.x/#dropped-dangerously-from-dangerouslygetparent-and-dangerouslygetstate

React v6
Dropped dangerously from dangerouslyGetParent and dangerouslyGetState​ The dangerouslyGetParent and dangerouslyGetState methods on the navigation prop are useful in many scenarios, and sometimes necessary. So we dropped the dangerously prefix to make it clear that it's safe to use. Now you can use navigation.getParent() and navigation.getState().

like image 75
Flewz Avatar answered Dec 03 '25 00:12

Flewz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!