how to pass a child component's validated data (as a formik form) to its parent component and handle form submission in parent

后端 未结 1 1194
灰色年华
灰色年华 2021-01-25 03:46

Is there a way to pass formik form values from a child component to a parent component and handle form submission in parent component only. I have a use case where I\'m building

相关标签:
1条回答
  • 2021-01-25 04:11

    by using props you can achieve this.

    Screen 1:

    render(
     <View>
              <Screen2
                onValueChange={() => {
                  this.setState({formProps: formProps});
                }}
              />
              <FormButton
                formProps={this.state.formProps}
                // @ts-ignore
                onPress={formProps.handleSubmit}
                // tslint:disable-next-line:no-duplicate-string
                title={'checkout'}
              />
            </View>
    )
    

    Screen 2:

    if (onValueChange) {
         onValueChange(formProps);
     }
    
    0 讨论(0)
提交回复
热议问题