Hieu Bui Hieu Bui - 2 months ago 18
Javascript Question

Uncaught TypeError: (0 , _store.configureStore) is not a function

store.js

import {createStore, applyMiddleware} from 'redux';
import createLogger from 'redux-logger';
import rootReducer from './reducers/index';

const logger = createLogger();

const createStoreWithMiddleware = applyMiddleware(logger)(createStore);

export default function configureStore(initialState) {
return createStoreWithMiddleware(rootReducer, initialState);
}


index.js

import React from 'react';
import ReactDOM from 'react-dom';
import TrackList from './components/TrackList';
import {configureStore} from './store';
import * as actions from './actions';

const tracks = [
{
id: 1,
title: 'Title 1'
},
{
id: 2,
title: 'Title 2'
}
];

const store = configureStore();
store.dispatch(actions.setTracks(tracks));

ReactDOM.render(
<TrackList />,
document.getElementById('app')
);


Folder src consist index.js and store.js

Show message Uncaught TypeError: (0 , _store.configureStore) is not a function when F12

Help me thanks

Answer

You export a single function from your module, so your import should be:

import configureStore from './store';

You would use

import {configureStore} from './store';

if your export looked like

export default {
  configureStore: function(initialState) {
    return createStoreWithMiddleware(rootReducer, initialState);
  }
}
Comments