withNavigationFocus React-Navigation alternative for class component after upgrade from 3.x to 6.x

Viewed 401

I am currently updating the version of my application, and I have a function that is used that no longer exists, I tried several things according to the documentation but I get either an "Invalid Hook Call" error or something else...

The problem without the withNavigationFocus function is that when the screen is rendered, the data is not displayed. I have to press Cmd+S to refresh and have the data on the screen. Knowing that the props are linked to Redux.

This is the line that causes the problem:

export default withNavigationFocus(connect(mapStateToProps, mapDispatchToProps)(Home));

I can't find an alternative so far, does anyone have an idea?

Upgrade doc link here

1 Answers

You can install a backward compatibility package and you can continue to use HOCs withNavigation and withNavigationFocus.

Inpm install @react-navigation/native@^5.x @react-navigation/compat@^5.x @react-navigation/stack@^5.x

It was designed with React Navigation 5. I didn't test with version 6

Related