DEV Community

Discussion on: Using React Navigation with Functional Components

Collapse
 
kiwipedro profile image
kiwipedro

Thanks Harshil, that's really helpful. How would you handled setParams to make the header dynamic?

Collapse
 
corsal8 profile image
Corsal8

Hi! I'm not the OP, but I've made the header dynamic by passing to the Home.navigationOptions function the navigation parameter like so:

Home.navigationOptions = navigation => ({
  title: navigation.navigation.getParam('name', 'John Doe')
});

This should work based on the React Navigation doc (reactnavigation.org/docs/en/header...).

Last but not least, I'm completely new to React Native, so take my answer with a grain of salt :)

Collapse
 
kiwipedro profile image
kiwipedro

Thanks @corsal8 , not quite what I meant: if you look on the same react-native doc it's the setParam function I'm trying to use. Not sure of the syntax when using it in a functional component compared to the class component that the docs exemplify :)

Collapse
 
harshil1712 profile image
Harshil Agrawal

Hey kiwipedro I am glad that the article could help. To use the setParams() method the structure is similar to navigate() method as shown in the article above, navigation.setParams({...})