-
-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tab.screen has always re-render when switch tabs #10174
Comments
Couldn't find version numbers for the following packages in the issue:
Can you update the issue to include version numbers for those packages? The version numbers must match the format 1.2.3. |
@bumjin1013 We are facing same issue on iOS. Were you able to work around this? |
This comment was marked as spam.
This comment was marked as spam.
All the screens get rendered while switching b/w tabs(@react-navigation/material-top-tabs). |
Same here. All of the tabs are re-redering when I switch between them |
same here, facing same issue in both Android + iOS, using the bottom tab https://reactnavigation.org/docs/5.x/bottom-tab-navigator |
Hey! Thanks for opening the issue. Can you provide a minimal repro which demonstrates the issue? Posting a snippet of your code in the issue is useful, but it's not usually straightforward to run. A repro will help us debug the issue faster. Please try to keep the repro as small as possible and make sure that we can run it without additional setup. The easiest way to provide a repro is on snack.expo.dev. If it's not possible to repro it on snack.expo.dev, then please provide the repro in a GitHub repository. |
Did anyone figure out why this happening??? |
Hello 👋, this issue has been open for more than a month without a repro or any activity. If the issue is still present in the latest version, please provide a repro or leave a comment within 7 days to keep it open, otherwise it will be closed automatically. If you found a solution or workaround for the issue, please comment here for others to find. If this issue is critical for you, please consider sending a pull request to fix it. |
Please read this doc -> https://reactnavigation.org/docs/troubleshooting#screens-are-unmountingremounting-during-navigation If you still have an issue, please give a snack repro that renders a component, not a console.log, in your case console.log is seen as a new change on each render & it is fired every time you switch tab |
Hey! This issue is closed and isn't watched by the core team. You are welcome to discuss the issue with others in this thread, but if you think this issue is still valid and needs to be tracked, please open a new issue with a repro. |
Why is this closed? |
Why did you closed it ? @raajnadar |
This issue is open for a long time without a minimal reproducer, you cannot expect maintainers to dig into your codebase to find the bug nor the version are added correctly to see if the issue is solved in the latest versions @sanduluca why don't you provide a minimal reproducer? I am happy to reopen the issue if you can provide one |
Here I have a simple tab navigator inside a stack navigator. Whenever I switch tabs I get this re-render:
const TabNav = createBottomTabNavigator();
const renderTabBarButton = props => {
return (
<TouchableOpacity {...props}>
<Text style={{color: 'red'}}>{props.to}</Text>
</TouchableOpacity>
)
}
const TAB_OPTIONS = () => ({
tabBarButton: renderTabBarButton
})
const TestNavigator = () => {
return (
<TabNav.Navigator>
<TabNav.Screen options={TAB_OPTIONS()} name={'tab1'} component={TestScreen}/>
<TabNav.Screen options={TAB_OPTIONS()} name={'tab2'} component={TestScreen}/>
</TabNav.Navigator>
)
}
const StackNav = createNativeStackNavigator();
const Main = () => {
return (
<StackNav.Navigator>
<StackNav.Screen name={'tabs'} component={TestNavigator}/>
<StackNav.Screen name={'asd'} component={TestScreen}/>
</StackNav.Navigator>
)
}
class App {
render() {
return (
<NavigationContainer>
<Main/>
</NavigationContainer>
);
}
} |
Hey @constantinescu-vlad, Why are you passing options as a function? This way every time you are creating a new reference to the returned object. Please replace this: const TAB_OPTIONS = () => ({
tabBarButton: renderTabBarButton
})
const TestNavigator = () => {
return (
<TabNav.Navigator>
<TabNav.Screen options={TAB_OPTIONS()} name={'tab1'} component={TestScreen}/>
<TabNav.Screen options={TAB_OPTIONS()} name={'tab2'} component={TestScreen}/>
</TabNav.Navigator>
)
} with: const TAB_OPTIONS = {
tabBarButton: renderTabBarButton
}
const TestNavigator = () => {
return (
<TabNav.Navigator>
<TabNav.Screen options={TAB_OPTIONS} name={'tab1'} component={TestScreen}/>
<TabNav.Screen options={TAB_OPTIONS} name={'tab2'} component={TestScreen}/>
</TabNav.Navigator>
)
} |
okwasniewski hey thanks for the reply. It doesnt matter how I write the tab navigator options. the StaticContainer still re-renders unnecessarily |
@constantinescu-vlad I've just checked your comment one more time. StaticContainer is supposed to rerender every time you change a route and it prevents child routes from rerendering. So this is not a bug. |
@okwasniewski ok got it, thank you for your information |
@constantinescu-vlad hey man, did you manage to solve this issue? |
@wilmxre no, I still get the re-render |
Yes, re-render all tab screens when tab is changed |
I'm also facing same issue! |
I had a similar issue, when i switch between two tabs for example, every component was re-rendered. The problem was that I was passing a Contextprovider as a child of NavigationContainer, i level up my ContextProvider and the re-renders stopped |
yeah, a context provider caused the re-rendering for me too |
Try what i said in my previous comment, that fixed it |
This comment was marked as resolved.
This comment was marked as resolved.
Yes this solution worked for me too , thanks |
Current behavior
I'm using TopTabNavigator from '@react-navigation/material-top-tabs.
When i switch tab screen, the components are re-rendered at once again.
<Tab.screen
component={console.log('first component')}
/>
<Tab.screen
component={console.log('second component')}
/>
<Tab.screen
component={console.log('third component')}
/>
Every time swich tabs, all console logs are executed at once
Expected behavior
I want prevent re-rerendering, just render only once
Reproduction
https://github.com/bumjin1013/node-react-food-delivery.git
Platform
Packages
Environment
The text was updated successfully, but these errors were encountered: