react-redux connect连接器
ps: 用于记录学习, 持续更新
在使用react-redux的时候会用到connect, 这个会帮我们自动创建容器组件,用法如下:
1. connect()(),第一个(), 传入两个函数
import { connect } from 'react-redux'
class Person extends Components {
}
// 这不是简写
const funa = (state) => {
return {type: state }
// 这样的写法相当于 <Person type={state }>
}
const funb = (dispatch) => {
return () => {
dispatch({type: 'adsf', value: 'adfadsfasdf'})
}
}
//这是简写
// state 就是 redux存储的所有的总状态对象
export default connext(
// 映射状态
// 自定义的字段 用于上面的UI组件
state => ({ '自定义的字段': state }),
// 映射操作状态的方法
{
自定义的方法名: action方法名,
zidingyi: dispatch(action方法名)
}
)(Person)
// 在简写中 自定义的字段可以在UI组件中 这个使用 this.props.自定义方法名; 或者 this.props.自定义的字段