简体   繁体   中英

createStore is @deprecated so im trying to replace with configurationStore

createStore is @deprecated so im trying to replace with configurationStore, i think the post data from my cluster is not showing because of that

 ``` import React from 'react'; import ReactDom from 'react-dom/client'; import { Provider } from 'react-redux'; import {createStore, applyMiddleware, compose } from 'redux'; import thunk from 'redux-thunk'; import reducers from "./reducers"; import App from './App' const store = createStore(reducers, (compose(applyMiddleware(thunk)))) const root = ReactDom.createRoot(document.getElementById("root")); root.render( <Provider store={store}> <App /> </Provider> );


And im trying to do it like this:

    

 import React from 'react'; import ReactDom from 'react-dom/client'; import { Provider } from 'react-redux'; import { applyMiddleware, compose } from 'redux'; import thunk from 'redux-thunk'; import { configureStore } from '@reduxjs/toolkit' import reducers from "./reducers"; import App from './App' const store = configureStore(reducers, (compose(applyMiddleware(thunk)))) const root = ReactDom.createRoot(document.getElementById("root")); root.render( <Provider store={store}> <App /> </Provider> ); ```

Of Course it didn't work i'm trying to figure out how it could be

You would do

const store = configureStore({ reducer: reducers })

The thunk middleware is active automatically. compose and applyMiddleware are not needed any more. So is combineReducers .

If you had

const reducers = combineReducers({
  a: reducerA,
  b: reducerB
})

you could also just instead do

const store = configureStore({ 
  reducer: {
    a: reducerA,
    b: reducerB
  }
})

If you were still using createStore , that means that you were generally using an outdated style of Redux that is about 4x times the code of modern Redux.

Modern Redux does not use switch..case reducer, ACTION_TYPE constants, immutable reducer logic, hand-written action creators or connect & mapStateToProps . You might have been misled by an outdated tutorial.

I would highly recommend you to follow the official Redux tutorial which will leave you with knowledge of modern Redux and in the end much cleaner and easy to maintain code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM