如何使用来自自定义JSON的mapStateToProps作为prop初始化redux表单中的值?
我正在构建一个redux表单,在这里我希望通过存在于不同JSON对象中的道具来获得初始值 我作为道具传递的JSON对象的结构是:-如何使用来自自定义JSON的mapStateToProps作为prop初始化redux表单中的值?,json,reactjs,redux,react-redux,redux-form,Json,Reactjs,Redux,React Redux,Redux Form,我正在构建一个redux表单,在这里我希望通过存在于不同JSON对象中的道具来获得初始值 我作为道具传递的JSON对象的结构是:- "Team": { "Manager": { "name": "Tom" }, "members": { "PD" : { "SE": { "name" : "SAM" } } } }, 我的red
"Team": {
"Manager": {
"name": "Tom"
},
"members": {
"PD" : {
"SE": {
"name" : "SAM"
}
}
}
},
我的redux表单有两个字段,我需要将初始状态填充为Tom和SAM
我正在调用具有如下redux表单的类:-
ReactDOM.render(
<Provider store={store}><Emp empJSON={}/></Provider>,
document.querySelector('#tenant-content')
);
我也有一个功能
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,
}
}}
但是,控制台上未打印任何内容,也未设置初始值
我做错什么了吗?我不确定是否有办法将
MapStateTrops
直接传递到redux表单,就像这样--您是否缺少连接
Emp = connect(mapStateToProps)(Emp);
export default reduxForm({
form: 'empForm', // a unique identifier for this form
onSubmit: submit,
})(Emp);
请参见哦,我是按照git hub的帖子来做这件事的。我要试试这个
Emp = connect(mapStateToProps)(Emp);
export default reduxForm({
form: 'empForm', // a unique identifier for this form
onSubmit: submit,
})(Emp);