rai*_*400 7 react-native redux-form
我有一个redux-form,我正在尝试初始化表单initialValues.鉴于以下代码,表单未填充名称或年龄:
const EmployeesForm = reduxForm({
form: 'addEmployee',
enableReinitialize: true
})(EmployeesFormComponent)
export default connect((state, ownProps) => {
const initialValues = { name: 'Jason', age: 24 }
return {
initialValues: initialValues
}
})(EmployeesForm)
Run Code Online (Sandbox Code Playgroud)
但是在检查next stateon redux 的web开发控制台中,我可以看到form.values并且form.initial都是包含这些initialValue值的Map对象.
我应该如何转换对象以使其"适合"到表单中.BTW我正在使用:import { Field, reduxForm } from 'redux-form/immutable'它是redux-form 6.8.0.
这可能是您的反应本机字段定义的问题。
<Field name="name" component={TextInput} />
<Field name="age" component={TextInput} />
Run Code Online (Sandbox Code Playgroud)
确保这是您表单的正确定义。如果可以的话,请也添加组件标记,以便它变得易于调试。
另外,react-native 与 redux-form 中的一个更棘手的部分是 onChangeText 回调而不是 onChange,因此为了解决这一问题,您必须在react-native TextInput 组件周围创建一个包装器
const TextInputNative = ({ input: { onChange, ...inputProps }}) => {
return <TextInput onChangeText={onChange}
{...inputProps} />
}
const EmployeesFormComponent = () => (
<Field name="name" component={TextInputNative} />
<Field name="age" component={TextInputNative} />
);
Run Code Online (Sandbox Code Playgroud)
这也可能会阻止您的表单更新初始值。
| 归档时间: |
|
| 查看次数: |
285 次 |
| 最近记录: |