Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
160
rated 0 times [  161] [ 1]  / answers: 1 / hits: 15534  / 8 Years ago, sun, september 18, 2016, 12:00:00

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


More From » redux

 Answers
14

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);
}
}

[#60682] Thursday, September 15, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
micayla

Total Points: 148
Total Questions: 92
Total Answers: 109

Location: Aruba
Member since Sat, Oct 2, 2021
3 Years ago
micayla questions
Fri, Dec 24, 21, 00:00, 3 Years ago
Thu, Apr 16, 20, 00:00, 4 Years ago
Thu, Nov 14, 19, 00:00, 5 Years ago
;