two submit on 1 Formik?

Viewed 2857

this is my code:

<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>

as you can see i have toggle and Input. I am just wondering if it's possible to do maybe 2 submits on toggle and input for 1 Formik?

1 Answers

Sure you can. Your code for submit will be like:

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

And there shown example from docs.

Related