两个提交 1 Formik?

two submit on 1 Formik?

这是我的代码:

<Formik
      initialValues={{
        email: 'eve.holt@reqres.in',
        password: '',
      }}
      validationSchema={TodoInputSchema}
      onSubmit={values => {
        // handleToggle
        // handleTodoInputSubmit
      }}>
      {({values, handleChange, handleSubmit, touched, errors}) => (
        <View style={styles.inputContainer}>
          <TouchableOpacity>
            <Text
              style={[
                styles.completeAll,
                todos.every(({complete}) => complete) &&
                  styles.completeFilterColor,
              ]}>
              {String.fromCharCode(10003)}
            </Text>
          </TouchableOpacity>
          <TextInput
            editable={!loading}
            returnKeyType="done"
            onSubmitEditing={handleAddTodo}
            blurOnSubmit={false}
            placeholder="What needs to be done?"
            style={styles.input}
            onChangeText={newText => setNewTodoText(newText)}
            value={newTodoText}
          />
          )}
        </View>
      )}
    </Formik>

如您所见,我有切换和输入。我只是想知道是否可以在切换时提交 2 次并输入 1 个 Formik?

当然可以。您的提交代码如下:

onSubmit={(values) => {
     handleToggle();
     return handleTodoInputSubmit(values);
}}>

并且 there 显示了来自文档的示例。