为了账号安全,请及时绑定邮箱和手机立即绑定

函数未定义 store.getState()

函数未定义 store.getState()

catspeake 2021-06-29 09:07:11
我在 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())


查看完整回答
反对 回复 2021-07-08
  • 3 回答
  • 0 关注
  • 243 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信