【问题标题】:How to implement the value from redux store to tabBarBadge?如何实现从 redux store 到 tabBarBadge 的值?
【发布时间】:2020-11-05 21:16:45
【问题描述】:

所以我已经从我的应用程序中实现了 redux,我还可以从 redux 中访问值我的问题是如何将 redux 中的值实现到特定屏幕,即使我没有打开我想要徽章的屏幕显示出来。

navigation.setOptions({
       tabBarBadge:
         store.getState().notif.count === 0
           ? null
           : store.getState().notif.count,
     });

【问题讨论】:

    标签: react-native react-redux react-navigation


    【解决方案1】:

    指定您定义屏幕的徽章,而不是使用setOptions

    const count = useSelector(state => state.notif.count);
    
    return (
      <Tab.Navigator>
        <Tab.Screen
          name="Whatever"
          component={Whatever}
          options={{
            tabBarBadge: count
          }}
        />
        {/* ...other screens */}
      </Tab.Navigator>
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多