createStore函数返回未定义的存储对象

时间:2019-07-22 10:35:36

标签: javascript react-native redux react-redux

我是React Native的新手,正在创建一些示例应用程序。因此,在使用了一个教程应用程序之后,我试图创建一个包含Redux商店的出租车预订应用程序。

所以我的App.js文件如下所示:


import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View
} from 'react-native';
import Root from "./src/main";
export default class TaxiApp extends Component {
  render() {
    return (
      <View style={styles.container}>
        <Root {...this.props}/>
      </View>
    );
  }
}

main.js文件如下:

import React from "react";
import createStore from "./store/createStore";
import AppContainer from "./AppContainer";

export default class Root extends React.Component{
    renderApp(){
        const initialState = window.___INITIAL_STATE__;
        const store = createStore(initialState);

        return(
            <AppContainer store={store}/>
        );
    }
    render(){
        return this.renderApp();

    }
}

AppContainer组件如下:

import React, {Component, PropTypes} from "react";
import {Router} from "react-native-router-flux";
import {Provider} from "react-redux";
import scenes from "../routes/scenes";

export default class AppContainer extends Component{
    static propTypes = {
        store : PropTypes.object.isRequired
    }
    render(){
        return(
            <Provider store={this.props.store}>
                <Router scenes={scenes}/>
            </Provider>
        )
    }
}

根组件的createStore()函数如下:

import { createStore, applyMiddleware, compose } from "redux";
import thunk from "redux-thunk";
import makeRootReducer from "./reducers";
import { createLogger } from "redux-logger";
import  createSocketIoMiddleware  from "redux-socket.io";

import io from "socket.io-client/dist/socket.io";

let socket = io("http://localhost:3000", {jsonp:false});

let socketIoMiddleware = createSocketIoMiddleware(socket, "server/");

const log =  createLogger({ diff: true, collapsed: true });

// a function which can create our store and auto-persist the data
export default (initialState = {}) => {

    // ======================================================
    // Middleware Configuration
    // ======================================================
    const middleware = [thunk, log, socketIoMiddleware];

    // ======================================================
    // Store Enhancers
    // ======================================================
    const enhancers = [];

    // ======================================================
    // Store Instantiation
    // ======================================================
    const store = createStore(
        makeRootReducer(),
        initialState,
        compose(
            applyMiddleware(...middleware),
            ...enhancers
        )
    );
    return store;
};


在尝试在android模拟器中运行此程序时,出现以下错误:

  

未定义不是对象(正在评估'_react.PropTypes.object')

如果有人可以帮助,那就太好了。在此先感谢!

1 个答案:

答案 0 :(得分:0)

您需要执行以下操作

import PropTypes from 'prop-types';

从react包中删除导入原型