【发布时间】:2019-07-10 17:13:29
【问题描述】:
我有一个“虚拟”字段inspection.images,我需要使用setFieldValue 从子组件更新它,但它没有更新。我做错了什么?
parent-component.js
...
<Formik
initialValues={{
inspection: {images:[]}
}}
onSubmit={values => {
console.log('form values: ');
console.log(JSON.stringify(values, null, 2));
}}
render={({values, isValid, handleSubmit, setFieldValue, errors}) => (
<View style={styles.screen}>
<Walkthrough onChanged={this.onWalkThroughIndexChanged}>
<InspectionForm navigation={this.props.navigation} values={values} setFieldValue={setFieldValue}
mediaObjectsHandler={this.mediaObjectsHandler.bind(this)}/>
</Walkthrough>
</View>
)}
/>
child-component.js
...
export class InspectionForm extends React.Component {
constructor(props) {
super(props);
this.state = {
inspectionMedia: [],
progress: 0,
};
props.setFieldValue('inspection.images', [...props.values.inspection.images, 'xxxx.png']);
}
render() {
return (
...
);
};
}
【问题讨论】:
-
您是否遇到任何错误?
标签: reactjs react-native state formik