Raul
Raul

Reputation: 3081

React Navigation 5 - Pass params to tab screen

I have the following Tab Navigator:

const [counter, setCounter] = useState(10);

return (
  <Tab.Navigator>
    <Tab.Screen name="Activity" />
  </Tab.Navigator>
);

How can I pass my "counter" state to the Tab Screen as route param?

Note: The counter can change, it is just a value listened from my database.

Upvotes: 0

Views: 388

Answers (1)

Abraham
Abraham

Reputation: 9845

The simplest way to do it is like this:

const [counter, setCounter] = useState(10);

return (
  <Tab.Navigator>
    {() => <Tab.Screen name="Activity" counter={counter}/>}
  </Tab.Navigator>
);

I have created a working snack for you: https://snack.expo.io/@abranhe/react-navigation-5

Upvotes: 2

Related Questions