我正在构建一个redux表单,我希望通过属性传递initialValues,这些属性存在于不同的JSON对象中。
我作为Props传递的JSON对象的结构是:
"Team": {
"Manager": {
"name": "Tom"
},
"members": {
"PD" : {
"SE": {
"name" : "SAM"
}
}
}
},我的redux表单有2个字段,我需要将初始状态填充为Tom和SAM
我调用具有如下redux形式的类:-
ReactDOM.render(
<Provider store={store}><Emp empJSON={}/></Provider>,
document.querySelector('#tenant-content')
);Emp类如下所示:
Emp.propTypes = {
empJSON: PropTypes.object,
};
Emp.defaultProps ={
empJSON:{},
}
export default reduxForm({
form: 'empForm', // a unique identifier for this form
onSubmit: submit,
},mapStateToProps )(Emp);
renderPartnerName.propTypes = {
input: PropTypes.object,
};我还有一个函数
function mapStateToProps(state, ownProps) {
// state will be the state of your redux store
// ownProps will be your component's props
console.log(state)
console.log(ownProps)
return {
initialValues: {
EmployeeName: ownProps.members.PD.SE.name,
}
}}但是,控制台上没有打印任何内容,也没有设置初始值。
我做错了什么吗?
发布于 2017-09-22 03:35:10
我不确定是否有办法将mapStateToProps直接传递给像这样的redux-form --您是否错过了connect
Emp = connect(mapStateToProps)(Emp);
export default reduxForm({
form: 'empForm', // a unique identifier for this form
onSubmit: submit,
})(Emp);请参阅http://redux-form.com/7.0.4/docs/faq/howtoconnect.md/
https://stackoverflow.com/questions/46351471
复制相似问题