FieldArray
组件不起作用。
我使用redux-form
包。
我的代码如下:
import React from 'react'
import { FieldArray, reduxForm } from 'redux-form'
import { connect } from 'react-redux'
const renderMembersPP = ({ fields, meta: { touched, error, submitFailed } }) => (
<ul>
{fields.map((member, index) =>
<li style={{width:'5',height:'5',backgroundColor:'red',color:"white"}} key={index}>
show?
</li>
)}
</ul>
)
let NextWeekDriftForm = (props) => {
const { handleSubmit, pristine, reset, submitting} = props
return (
<form onSubmit={handleSubmit}>
<div>
<FieldArray name="members" component={renderMembersPP}/>
</div>
{JSON.stringify(props.initialValues.members) }
</form>
)
}
NextWeekDriftForm = reduxForm({
form: 'NextWeekDriftForm', // a unique identifier for this form
})(NextWeekDriftForm)
export default NextWeekDriftForm = connect(
state => ({
initialValues: state.sendGood.driftMemberArray.formData,
})
) (NextWeekDriftForm)
{JSON.stringify(props.initialValues.members) }
呈现一些数据。
换句话说,members
是array
,它有价值。
我设置了fields.map
返回<li>show?<li/>
,但是,我没有看到show?
。
在我看来,结果应该是:
显示?
节目?
{JSON.stringify(props.initialValues.members)}的text
现在的结果是:
{JSON.stringify(props.initialValues.members)}的
text
答案 0 :(得分:0)
我添加enableReinitialize: true,
。现在,它运作良好。
export default NextWeekDriftForm = connect(
state => ({
initialValues: state.sendGood.driftMemberArray.formData,
enableReinitialize: true,
})
) (NextWeekDriftForm)