I'm using redux to store some values. One of these values is a boolean named "seen". It's updated to "false" whenever a new message (through websockets) arrive, and when the messages-screen is opened, it's updated to "true" again.
I also have a tabnavigator. In this tabnavigator, I have 4 buttons (icons): Home, Users, Messages and Settings.
Whenever the value of "seen" is "false", I want to show an extra icon in the tabnavigator to show users they have new messages. So I want to have access to the redux store in the tabnavigator.
My tabnavigator code is as follows:
const TabsNavigator = createMaterialTopTabNavigator(
{
Home: {
screen: Home,
navigationOptions: {
tabBarIcon: () => (
<Icon library="far" icon="home" color="black" size={25} />
)
}
},
Users: {
screen: Users,
navigationOptions: {
tabBarIcon: () => (
<Icon library="far" icon="users" color="black" size={25} />
)
}
},
Messages: {
screen: Messages,
navigationOptions: {
tabBarIcon: () => {
return (
<View>
// HERE I WANT TO HAVE ACCESS TO THE REDUX STORE (SEEN)
// I WANT TO SHOW AN ICON WHEN SEEN = FALSE
{seen === false &&
<Icon library="far" icon="exclamation" color="black" size={25} />
}
<Icon library="far" icon="comment" color="black" size={25} />
</View>
)}
}
},
Settings: {
screen: Settings,
navigationOptions: {
tabBarIcon: () => (
<Icon library="far" icon="cog" color="black" size={25} />
)
}
}
},
{
initialRouteName: 'Home',
tabBarPosition: 'bottom',
tabBarOptions: {
showIcon: true
}
}
)
How can I access the value of "seen" (in the redux store) in the tabnavigator? Adding useSelector(state => state.messages.seen) to the tabnavigator does not work, I get an error saying "hooks can only be called from the body of a functional component".