Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

formik provider

type Props = {
};
const FormUseFormik = (props: Props) => {
  const { enqueueSnackbar } = useSnackbar();

  const onSubmit = (values) => {
    enqueueSnackbar(`submit:  ${JSON.stringify(values)}`, {
      preventDuplicate: true,
      persist: false,
    });
  };

  const formikbag = useFormik<Values>({
    initialValues: {
      email: '',
      password: '',
    },
    onSubmit,
  });

  const { values, setFieldValue, handleSubmit } = formikbag;

  return (
    <Flex flex={1}>
      <Card width={800}>
        <Text mb={20}>Simple Formik</Text>
        <FormikProvider value={formikbag}>
          <Flex flexDirection='column'>
            <TextField
              placeholder='email'
              mb={20}
              value={values.email}
              onChange={(e) => setFieldValue('email', e.target.value)}
            />
            <TextField
              type='password'
              placeholder='password'
              mb={20}
              value={values.password}
              onChange={(e) => setFieldValue('password', e.target.value)}
            />
          </Flex>
          <Button
            type='submit'
            onClick={handleSubmit}
            >
            Submit
          </Button>
        </FormikProvider>
      </Card>
    </Flex>
  )
};

export default FormUseFormik;
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to get current year in javascript 
Javascript :: onclick focus out jquery 
Javascript :: set defaultValue for select element jsx 
Javascript :: how to make a if loop happen one 
Javascript :: run forset 
Javascript :: saturn range in angular display end date 
Javascript :: js class method called when page loads 
Javascript :: comment p5js 
Javascript :: animationframe javascript 
Javascript :: js take last item in array 
Javascript :: angular find value in json array 
Javascript :: remove file from input type file jquery 
Javascript :: check truthy or falsy javascript 
Javascript :: onchange event angular select 
Javascript :: mongoose generate new ObjectID 
Javascript :: ipv4 to int32 js 
Javascript :: top-level code javascript 
Javascript :: autofocus react 
Javascript :: jquery add items to select input 
Javascript :: settimestamp discord.js 
Javascript :: JavaScript check all checkboxes on page 
Javascript :: javascript string except last character 
Javascript :: math floor javascript null 
Javascript :: how to get visitor ip address in javascript 
Javascript :: javascript parse url parameters 
Javascript :: foreach jquery 
Javascript :: datatable row color 
Javascript :: angular generate component without spec 
Javascript :: how to make 1st letter capital in ejs 
Javascript :: mutation observer js 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =