我正在構建一個 React 本機應用程式,我正在使用帶有受保護路由的 react-native navigation-6 但是當我啟動該應用程式時出現此錯誤,我無法弄清楚為什么它沒有看到提供的 redux 存盤。
redux 設定得很好,我在應用程式中將它用于其他用途。

export default function App() {
const Stack = createNativeStackNavigator();
const { isLoggedIn } = useSelector((state) => state.auth);
return (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<StatusBar animated={true} barStyle='light-content' />
<PaperProvider>
<NavigationContainer>
<Stack.Navigator
initialRouteName='Login'
headerMode='screen'
options={{
headerTitle: (props) => (
<View style={styles.containerStyle}>
<DropDown
label={'Gender'}
mode={'outlined'}
value={category}
setValue={setCategory}
list={menuList}
visible={showDropDown}
showDropDown={() => setShowDropDown(true)}
onDismiss={() => setShowDropDown(false)}
inputProps={{
right: <TextInput.Icon name={'menu-down'} />,
}}
/>
</View>
),
headerStyle: {
backgroundColor: '#f4511e',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: 'bold',
},
}}
>
{isLoggedIn ? (
<>
<Stack.Screen name='Home' component={Home} />
<Stack.Screen
name='comments'
component={CommentsFeed}
/>
</>
) : (
<>
<Stack.Screen name='Login' component={Login} />
<Stack.Screen name='Register' component={Register} />
</>
)}
</Stack.Navigator>
</NavigationContainer>
</PaperProvider>
</PersistGate>
</Provider>
);
}
uj5u.com熱心網友回復:
App必須包裝在 provider 中,因為您正在其中使用useSelector。
export default function Wrapper(){
return (
<Provider store={store}>
<App />
</Provider>
)
}
應用程式
export default function App() {
const Stack = createNativeStackNavigator();
const { isLoggedIn } = useSelector((state) => state.auth);
return (
<PersistGate loading={null} persistor={persistor}>
<StatusBar animated={true} barStyle='light-content' />
.....
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/536488.html
上一篇:Laravel-如果我只有一個帶有電子郵件和ID的JWT令牌,我如何將Auth::attempt設定為用戶
下一篇:如何在護照中找到嵌套物件?
