Nella mia app redux js (google appengine backend), ricevo i seguenti avvisi e messaggi di errore quando viene aperta la pagina contenente il componente Root.Unchaught TypeError: store.getState non è una funzione
Attenzione: PropType riuscito: prop valido store
di tipo function
fornita al Provider
, previsto object
. Verifica il metodo di rendering di Root
. bundle.js: 6169
Attenzione: PropType riuscita: prop valido store
di tipo function
fornita al DevToolsWrapper
, attesi object
. Verifica il metodo di rendering di Root
. bundle.js: 6169
Avviso: impossibile tipi di contesto: contesto bambino non valido store
di tipo function
in dotazione per Provider
, attesi object
. Verifica il metodo di rendering di Root
. bundle.js: 6169
Avviso: impossibile tipi di contesto: contesto non valido store
di tipo function
in dotazione per Connect(AsyncApp)
, attesi object
. Verifica il metodo di rendering di Provider
.
Uncaught TypeError: store.getState is not a function
Questo è dove si verifica l'errore in lib/components/createConnect.js di react-redux.
function computeStateProps(store, props) {
var state = store.getState(); <<<<< The error occurs here.
var stateProps = shouldUpdateStateProps ? finalMapStateToProps(state, props) : finalMapStateToProps(state);
_invariant2['default'](_utilsIsPlainObject2['default'](stateProps), '`mapStateToProps` must return an object. Instead received %s.', stateProps);
return stateProps;
}
Al punto di interruzione, subito prima che si verifichi questo errore, console.log (archivio) restituisce questo.
function (reducer, initialState) {
var store = next(reducer, initialState);
var _dispatch = store.dispatch;
var chain = [];
var middlewareAPI = {
getState: store.…
Tuttavia, quando si esegue lo stesso codice esatto utilizzando Nodo backend, console.log (negozio) restituisce invece questo oggetto.
devToolsStore: Object
dispatch: (action)
getReducer: getReducer()
getState: getState()
replaceReducer: replaceReducer(nextReducer)
subscribe: subscribe(listener)
mio componente principale e configureStore.js si presenta così:
import React, { Component } from 'react';
import { Provider } from 'react-redux';
import configureStore from '../store/configureStore';
import { createStore, applyMiddleware, combineReducers, compose } from 'redux';
import { DevTools, DebugPanel, LogMonitor } from 'redux-devtools/lib/react';
import AsyncApp from './AsyncApp';
const store = configureStore();
export default class Root extends Component {
render() {
return (
<div>
<Provider store={store}>
{() => <AsyncApp />}
</Provider>
<DebugPanel top right bottom>
<DevTools store={store} monitor={LogMonitor} />
</DebugPanel>
</div>
);
}
}
configureStore.js
import { createStore, applyMiddleware, combineReducers, compose } from "redux";
import thunkMiddleware from "redux-thunk";
import loggerMiddleware from "redux-logger";
import rootReducer from "../reducers";
import thunk from 'redux-thunk';
import { devTools, persistState } from 'redux-devtools';
const finalCreateStore = compose(
applyMiddleware(thunkMiddleware),
devTools(),
persistState(window.location.href.match(/[?&]debug_session=([^&]+)\b/)),
createStore
);
export default function configureStore(initialState) {
return finalCreateStore(rootReducer, initialState);
}