gpt4 book ai didi

javascript - createStore 是@deprecated 所以我试图用 configurationStore 替换

转载 作者:行者123 更新时间:2023-12-05 01:51:09 25 4
gpt4 key购买 nike

createStore 已被@deprecated,所以我试图用 configurationStore 替换,我认为来 self 的集群的发布数据因此没有显示

```

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

```

当然没用,我想弄清楚它是怎么回事

最佳答案

你会做

const store = configureStore({ reducer: reducers })

thunk 中间件自动激活。 composeapplyMiddleware 不再需要了。 combineReducers 也是如此。

如果你有

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

你也可以这样做

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

如果您仍在使用 createStore,这意味着您通常使用过时的 Redux 风格,其代码量是现代 Redux 代码的 4 倍左右。

& mapStateToProps。您可能被过时的教程误导了。

我强烈建议您关注 official Redux tutorial这将使您了解现代 Redux,并最终使代码更加简洁和易于维护。

关于javascript - createStore 是@deprecated 所以我试图用 configurationStore 替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72479800/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com