react-native - redux 找不到 react-redux 上下文值
问题描述
为什么我收到此错误消息:
redux could not find react-redux context value; please ensure the component is wrapped in a <Provider>
我想在 AppLoading 使用调度,所以这是代码:
import React, { useState } from 'react';
import * as Font from 'expo-font';
import AppLoading from 'expo-app-loading';
import { View, Text} from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { Home } from './src/navigation/curvedNavigation';
import store from './src/redux/index';
import { Provider } from 'react-redux';
import { authSuccess } from './src/redux/slice/authSlice';
import * as SecureStore from 'expo-secure-store';
const App = () => {
const [contentLoad, setContentLoad] = useState(false);
const contentLoadFunc = async () => {
await Font.loadAsync({
'montserrat-regular': require('./assets/fonts/Montserrat-Regular.ttf'),
});
const userData = await SecureStore.getItemAsync('users');
const jwt = await SecureStore.getItemAsync('jwt');
const d = {
userData,
jwt
};
userData !== null && jwt !== null && store.dispatch(authSuccess(d));
};
const handleSetContent = () => {
setContentLoad(true);
};
return (
<Provider store={store}>
{ contentLoad === false ? <AppLoading startAsync={contentLoadFunc} onFinish={handleSetContent} onError={err => console.error(err)} /> : <Home /> }
</Provider>
)
};
export default App;
€:它有效,我从代码中删除了 useDispatch() 。..................................................
解决方案
推荐阅读
- python-3.x - 如何通过 for 循环为每个模块添加不同的颜色?喜欢下面的评论吗?
- node.js - 如何允许用户在api中添加参数?
- vue.js - 如何使用 Cypress e2e 快照测试和 Vue 停止更新 UI 快照
- c - NEON 在 IMX7 上具有与 C 相同的性能
- c# - C#:从 ADLS gen2 blob 下载大型 json 文件并反序列化到对象
- reactjs - 某些参数使用reactjs返回函数错误
- c# - 如何让 ListBox 显示来自文本框的“ID”的所有信息(ASP.NET C#)
- python - 包版本更改时获取 tox 以重新安装 console_scripts
- docker - docker 中的 Couchbase 进行集成测试:使端口 8092、8093、8094 和 8095 可配置以能够使用 docker 的随机端口
- javascript - 将 setTimeout 添加到 Promise.all