class FruitShop extends Component { constructor(props) { super(props) this.state = { jobDetailsList: [], fruitTitle: (typeof this.props.location.state !== 'undefined') ? this.props.location.state.fruitTitle : '', }; this.showFruitListDetails = this.showFruitListDetails.bind(this); } showFruitListDetails(fruitList) { this.setState({ fruitDetailsList: fruitList, }); let fruitTitleValue = JSON.parse(JSON.stringify(this.state.fruitDetailsList)).fruitTitle; this.setState({ fruitTitle: fruitTitleValue, }); } render() { return ( <Formik initialValues={{ fruitTitle: this.state.fruitTitle, }} render={({ errors, touched, isSubmitting, setFieldValue }) => ( !isSubmitting ? ( <Form> <div> <CloneNewFruitPage showFruitListDetailsHandler={this.showFruitListDetails} /> </div> <div className="form-group"> <label htmlFor="fruitTitle">Fruit Title</label> <Field name="fruitTitle" type="text" /> </div> </Form>) : (<PageSpinner />) )} /> );
答案 0 :(得分:0)
如果initialValues
值在运行时发生更改,则始终可以将属性enableReinitialize={true}
添加到Formik
组件中。
https://jaredpalmer.com/formik/docs/api/formik#enablereinitialize-boolean