redux与react-redux的区别:

redux简介:

redux是react中进行state状态管理的JS库(并不是react插件),一般是管理多个组件中共享数据状态。这个是和Vuex是一样的。

react-redux简介:

React-ReduxRedux的官方React绑定库。它能够使你的React组件从Redux store中读取数据,并且向store分发actions以更新数据。


①:redux和组件进行对接的时候是直接在组件中进行创建。react-redux是运用Provider将组件和store对接,使在Provider里的所有组件都能共享store里的数据,还要使用connect将组件和react连接。

图解:

在组件中使用redux创建store和使用:

redux与react-redux的区别:

使用react-redux

redux与react-redux的区别:

redux与react-redux的区别:

②:获取state的方式不一样

redux获取state是直接通过store.getState()。

react-redux获取state是通过mapStateToProps函数,只要state数据变化就能获取最新数据

redux与react-redux的区别:

redux与react-redux的区别:

③触发action的方式不一样。

redux是使用dispatch直接触发,来操作store的数据。

react-redux是使用mapDispathToProps函数然后在调用dispatch进行触发

如图:

react触发action

redux与react-redux的区别:

react-redux触发action(下面的dispatch方法只不过是将action的type拆分了)

action组件中定义的类型

redux与react-redux的区别:

在组件中导入action类型

redux与react-redux的区别:

redux与react-redux的区别:

组件调用方式触发action

redux与react-redux的区别:

结尾:

      分享:骚年啊,还得奋斗啊!