我在 React Native 中的商店遇到了一些问题。我在我的文件 store/index.js 中配置了 store。我将它导出,然后导入 App.js。来自reducer的动作被正确执行,记录器在浏览器调试器中显示动作,但有一个问题“函数未定义store.getState()。当我在浏览器控制台中输入“store.getState()”时,我得到一个问题“store未定义”。我不知道可能有什么问题:/感谢您的帮助!我的文件存储/index.js:import { createStore, combineReducers, applyMiddleware, compose } from 'redux';import { default as mailReducer } from './Mail';import { default as authReducer } from './Auth';import { navReducer } from './Navigation';import { logger } from 'redux-logger';import { composeWithDevTools } from 'redux-devtools-extension';import { combineEpics, createEpicMiddleware } from 'redux-observable';import { middleware as navMiddleware } from "../navigation";const rootReducer = combineReducers({ points: mailReducer, auth: authReducer,});const initialState = {};const store = createStore( rootReducer, applyMiddleware(logger));export default store;我的文件 App.js:import React, {Component} from 'react';import {Platform, StyleSheet, Text, View} from 'react-native';import { createStackNavigator, createAppContainer } from "react-navigation";import { default as NavigationComponent } from './navigation';import store from "./store/index.js";import { IntlProvider, addLocaleData} from "react-intl";import messages_pl from "./formattedMessages/pl.json";import locale_pl from 'react-intl/locale-data/pl';import { connect, Provider } from "react-redux";addLocaleData([...locale_pl]);global.Intl = require('intl');const messages = { 'pl': messages_pl,};const initialState = {};export default class App extends Component<Props> { render() { return ( <Provider store={store}> <IntlProvider locale="pl" messages={messages["pl"]} textComponent={Text}> <NavigationComponent /> </IntlProvider> </Provider> ); }}
3 回答
郎朗坤
TA贡献1921条经验 获得超9个赞
如果你使用 'redux-persists' 并从 ../store 返回 {store,persistor} 试试这个:
import returnStoreAndPersistor from "../../store";
const { store } = returnStoreAndPersistor()
console.log(store.getState())
添加回答
举报
0/150
提交
取消