2
我正在构建一个redux表单,我想通过在不同的JSON对象中存在的props传递initialValues。如何使用自定义JSON中的mapStateToProp作为prop来初始化redux表单中的值?
,我想过去当道具的JSON对象的结构是: -
"Team": {
"Manager": {
"name": "Tom"
},
"members": {
"PD" : {
"SE": {
"name" : "SAM"
}
}
}
},
我的终极版形式HAVS 2场,我需要填充的初始状态为汤姆和SAM
我调用具有终极版形式像这样的类: -
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,
}
}}
但是没有打印在控制台上也不是设置initialvalues。
我做错了什么?
哦,我跟着这个混帐枢纽后做this.https://github.com/erikras/redux-form/issues/916I应尝试了这一点 – 789