Alexander
Alexander

Reputation: 1378

making an action to fire when navigating through the app

I made a navigation using createMaterialBottomTabNavigator and I have a component thats being rendered when I switch to the screen using this navigation, I want to make the navigation to fire a function everytime I enter the screen using this navigation, something of a useEffect, I tried doing useEffect with an empty array [], but it doesn't work, is there a way to achieve this?

Upvotes: 0

Views: 204

Answers (1)

Guruparan Giritharan
Guruparan Giritharan

Reputation: 16354

You have to use the useFocusEffect hook which is similar to useEffect but it runs every time you navigate to a screen. But use effect will run only the first time. You can see the sample code in the docs

https://reactnavigation.org/docs/use-focus-effect/

Upvotes: 1

Related Questions