-
i want use some hooks in componentA and componentB, so i have to use them as function component, any help please? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I have a similar situation with the Current configuration (simplified) const Tab = createBottomTabNavigator<TabBarNavigatorParamList>();
export function TabNavigator() {
const state1 = useState1()
const state2 = useState2()
return (
<Tab.Navigator>
<Tab.Screen
name="Tab1"
component={Tab1}
options={{tabBarBadge: state1}}
/>
<Tab.Screen
name="Tab2"
component={Tab2}
options={{tabBarBadge: state2}}
/>
// [...]
</Tab.Navigator>
);
} What I would like to do (simplified) const Tab = createBottomTabNavigator<TabBarNavigatorParamList>();
export function TabNavigator() {
return (
<Tab.Navigator>
<Tab1 />
<Tab2 />
// [...]
</Tab.Navigator>
);
}
function Tab1() {
const state1 = useState1()
return (
<Tab.Screen
name="Tab1"
component={Tab1}
options={{tabBarBadge: state1}}
/>
);
}
function Tab2() {
const state2 = useState2()
return (
<Tab.Screen
name="Tab2"
component={Tab2}
options={{tabBarBadge: state2}}
/>
);
} Also it makes it more readable when you have many screens on a |
Beta Was this translation helpful? Give feedback.
-
React Navigation 7 supports a layout prop for the screen component that can be used to add a wrapper (such as a context provider) for the screen component. https://reactnavigation.org/docs/7.x/screen/#layout Reference - #11977 (comment) |
Beta Was this translation helpful? Give feedback.
React Navigation 7 supports a layout prop for the screen component that can be used to add a wrapper (such as a context provider) for the screen component.
https://reactnavigation.org/docs/7.x/screen/#layout
Reference - #11977 (comment)