Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

92
Views
how to create store with react-redux

Sorry for the silly question but i do not know how to combine together my existing redux store definition with applyMiddleware.

This is my current working code:

const store = createStore(
  combineReducers({
    ...reducers,
    routing: routerReducer
  })
)

I would like to add this middleware somehow to my store definition:

applyMiddleware(...thunk)

My solution does not work, I get a "TypeError: dbg is undefined" in the web browser:

const store = createStore(
  applyMiddleware(...thunk),
  combineReducers({
    ...reducers,
    routing: routerReducer
  })
)

Could you please give me a quick help? Thank you.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Try this

createStore(
  combineReducers({
    ...reducers,
    routing: routerReducer
  }), 
  applyMiddleware(thunk)
)

Syntax:

createStore(reducer, [preloadedState], [enhancer])

Enhancer must be the last parameter for createStore()

Read more from here

over 4 years ago · Santiago Trujillo Report

0

better solution:

app.js:

    import {createStore, applyMiddleware, compose} from 'redux';
    import {browserHistory, Router, Route, IndexRoute} from 'react-router';
    import {syncHistoryWithStore, routerMiddleware} from 'react-router-redux';
    import {reducers} from './reducers';

   const initial_state = {};

    let middleware = applyMiddleware(routerMiddleware(browserHistory));
        if (process.env.NODE_ENV !== 'production') {
            middleware = compose(middleware, window.devToolsExtension && window.devToolsExtension());
        }
        const store   = createStore(reducers, initial_state, middleware);
        const history = syncHistoryWithStore(browserHistory, store);

reducers:

import {combineReducers} from 'redux';
import {routerReducer} from 'react-router-redux';
import users from './users';

export const reducers = combineReducers({
    routing:routerReducer,
    users: users
});
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!