tgfischer / react-bootstrap-formik

A React library for creating forms with Bootstrap
MIT License
10 stars 2 forks source link

Get access to formik.isSubmitting #289

Open adambedford opened 2 years ago

adambedford commented 2 years ago

Is there a way to get access to formik.isSubmitting within the form to disable the submit button?

soren121 commented 2 years ago

Just roll your own Form component like so:

import { Formik } from 'formik';
import { Form } from 'react-bootstrap';

export const FormikComponent = ({ children, ...props }) => (
    <Formik {...props}>
        {(formikBag) => (
            <Form
                onSubmit={formikBag.handleSubmit}
                onReset={formikBag.handleReset}
            >
                {children(formikBag)}
            </Form>
        )}
    </Formik>
);
import { FormikComponent } from './formikComponent';
import { Form as RBF } from 'react-bootstrap-formik';
const { Input } = RBF;

<FormikComponent initialValues={{ email: '' }} onSubmit={handleSubmit}>
    {({ isSubmitting }) => (
        <Input name="email" label="Email" />
    )}
</FormikComponent>