reactjs - 使用 BottomTabNavigator 防止在状态更改后重新渲染
问题描述
每次我按下一个按钮来更改存储在与底部标签导航器链接的两个屏幕的上下文中的状态时,都会记录两次。当我使用堆栈导航器时也会发生同样的情况,如果我在导航到的屏幕中按下 tha 按钮,a 会被记录两次,就好像两个屏幕都重新呈现,即使其中只有一个是可见的。如何防止这种情况发生,只允许重新渲染实际可见的屏幕?
应用程序.js:
const navigator = createBottomTabNavigator(
{
Index: IndexScreen,
Test: tester
},
{
initialRouteName: 'Index',
}
);
const App = createAppContainer(navigator);
export default () => {
return (
<Provider>
<App />
</Provider>
);
};
IndexScreen.js:
const IndexScreen = () => {
const { state, ..., increment } = useContext(Context); //... represents some other methods here
console.log("a");
... //a button that just increments a number stored in state
}
tester.js 的结构类似于 IndexScreen.js 的结构。
解决方案
推荐阅读
- mysql - 即使安装了 mysql 并且 gem 存在,为什么我会收到此错误“安装 mysql2 (0.5.2) 时发生错误...”?
- java - 问题在“
" 标签试图将前端 maven-plugin 添加到 java proyect - c++11 - 使用未声明的标识符 __glibcxx_assert
- react-native - 将 React Router (native) 用于 React native?
- bash - 从标准输入读取数据时,如何防止“期望”在 EOF 退出?
- ajax - 在 WordPress 中获取 check_ajax_referer 的响应
- git - 如何在一个 GIT 存储库中使用带有多个 TYPO3 扩展的 Composer
- azure-dns - Azure 自定义域未针对 azure zone 记录进行验证
- angular - 我的多路由器出口链接在 Angular 中不起作用
- python - 如何从字符串更改为整数