1
我使用redux组件包装材质TextField。有些属性只能在mapStateToProps
中使用,不能传递给组件本身。否则,我得到Unknown prop
警告。指定未定义的值不会有帮助。删除mapStateToProps中的属性
function mapStateToProps(state = {}, ownProps) {
var dataKey = ownProps.dataKey;
return {
value: state[dataKey],
dataKey: undefined
}
}
const store = createStore(reducer, {stuff: 123});
const toDraw = <TextInput dataKey="stuff"/>
是否有任何删除从ownProps
在mapStateToProps
东西,而不是创建包装组件更简单的方法?
function mergeProps(stateProps, dispatchProps, ownProps) {
return Object.assign({}, ownProps, stateProps, dispatchProps);
}
写自己的版本,樱桃挑选你要发送到您的组件道具: