简体   繁体   中英

Formik throwing Error: JSX props should not use functions in React

This test.tsx :

       <Form>
          <Field name='name' validate={validateFunc}>
            {({ field, form }) => (
                <FormControl isInvalid={form.errors.name && form.touched.name}>
                  <FormLabel htmlFor='name'>Default</FormLabel>
                  <Input {...field} id='name' placeholder='name' />
                  <FormErrorMessage>{form.errors.name}</FormErrorMessage>
                </FormControl>
            )}
          </Field>

yields

Error: JSX props should not use functions  react/jsx-no-bin

I know why this is bad, but I don't know how to change it.

<Field name='name' validate={() => validateFunc}>
  {({ field, form }) => (
      <FormControl isInvalid={form.errors.name && form.touched.name}>
        <FormLabel htmlFor='name'>Default</FormLabel>
        <Input {...field} id='name' placeholder='name' />
        <FormErrorMessage>{form.errors.name}</FormErrorMessage>
      </FormControl>
  )}
</Field>

maybe you can try this to fix your problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM