首页 > 解决方案 > 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() 。..................................................

标签: react-nativereduxexpo

解决方案


推荐阅读