React中的createStore和createStoreWithMiddleware有什么区别? [英] what is the difference between createStore and createStoreWithMiddleware in react?

查看:72
本文介绍了React中的createStore和createStoreWithMiddleware有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了两种配置redux createStore的方法,

I found two ways to configure redux createStore ,

1. https://github.com/TeamWithBR/SampleProjectTodo/blob/master/src/store/configureStore.js

2. https://github.com/aknorw/piHome/blob/9f01bc4807a8dfe2a75926589508285bff8b1ea6/app/configureStore.js

哪个更可取?

推荐答案

createStoreWithMiddleware 是在Redux中使用增强器创建商店的旧方法.在 Redux版本3.1.0 中,引入了一种新方法,现在 createStore 接收增强器,例如 applyMiddleware()作为最后一个可选参数.

createStoreWithMiddleware is the old way to create the store with enhancers in Redux. In Redux version 3.1.0, a new approach has been introduced and now createStore receives an enhancer such as applyMiddleware() as the last optional argument.

现在,新的 createStore 方法是可取的,因为它可以使代码更易于阅读和推理,但是两者都可以使用.

Now, the new createStore approach is preferable as it leads to code that is easier to read and reason about, but both will work.

这篇关于React中的createStore和createStoreWithMiddleware有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆