Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 652
Hieu Bui Avatar asked Sep 18 '16 12:09

Hieu Bui


1 Answers

Edited on March 11th 2019:

This answer will likely no longer work. Please see discussion in comments below as to why, and what should be the actual solution.


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);
  }
}
like image 173
Mchl Avatar answered Sep 18 '22 05:09

Mchl