Aquí está mi código:
tienda.js
import {createStore, applyMiddleware, compose} from 'redux'; import {fromJS} from 'immutable'; import {routerMiddleware} from 'react-router-redux'; import createSagaMiddleware from 'redux-saga'; import createReducer from './reducers'; const sagaMiddleware = createSagaMiddleware(); export default function configureStore(initialState = {}, history) { // Create the store with two middlewares // 1. sagaMiddleware: Makes redux-sagas work // 2. routerMiddleware: Syncs the location/URL path to the state const middlewares = [sagaMiddleware, routerMiddleware(history)]; const enhancers = [applyMiddleware(...middlewares)]; const store = createStore(createReducer, fromJS(initialState), enhancers); // Extensions store.runSaga = sagaMiddleware.run; store.asyncReducers = {}; // Async reducer registry return store; }Rutas.js
import React from 'react'; import {Route, Router, IndexRoute, browserHistory} from 'react-router'; import {syncHistoryWithStore} from 'react-router-redux'; import store from './store'; import Welcome from './containers/Welcome'; const history = syncHistoryWithStore(browserHistory, store); const routes = ( <Router history={history}> <Route path="/"> <IndexRoute component={Welcome} /> </Route> </Router> ); export default routes;Índice.js
import React from 'react'; import ReactDOM from 'react-dom'; import {browserHistory} from 'react-router'; import { Providers } from 'react-redux'; import configureStore from './store'; import routes from './routes'; const initialState = {}; const store = configureStore(initialState, browserHistory); ReactDOM.render( <Provider store={store}> {routes} </Provider>, document.getElementById('main-content') );No puedo encontrar dónde está el culpable. Traté de depurarlo, pero no puedo encontrar qué es lo que realmente lo convierte en ese error. error: TypeError no detectado: store.getState no es una función
¿Alguna solución?
Este es un error tipográfico que generó el error: TypeError: store.getState is not a function
Equivocado
const store = createStore(()=>[], {}, applyMiddleware);Correcto
const store = createStore(()=>[], {}, applyMiddleware()); Observe el paréntesis agregado () en applyMiddleware .
Tenga en cuenta que en su Routes.js , la store no se inicializa correctamente. Deberías agregar estas líneas:
const initialState = {}; const store = configureStore(initialState, browserHistory); como en su archivo index.js .
Estaba haciendo esto (un requerimiento dinámico) ..
const store = require('../store/app') state = store.getState() pero por alguna razón cuando usas require en lugar de import tienes que hacer esto...
const store = require('../store/app') state = store.default.getState()