code converter from javascript to typescript 1

code converter from javascript to typescript

 const  Validacao =() => {
     const {getFieldProps, handleSubmit, isValid} = useFormik({
        initialValues: {
            name:'',
            contact:{
            email:'',
            phone:''
        }
       },
       validate: values => {
        const err ={}
        const message= ' campo obrigatorio'
        if(!values.name) err.name = message
        if(!values.contact.email) err.email = message
        return err
    },
    onSubmit: (values, bag) => {
    console.log(values)
  }
})
const [name, metadataName] = getFieldProps('name','text')
const [email, metadataEmail] = getFieldProps('contact.email', 'text')
const [phone, metadataPhone] = getFieldProps('contact.phone', 'text')

Here is what the above code is Doing:
1. We’re using the useFormik hook to create a formik instance.
2. We’re passing the initial values to the formik instance.
3. We’re passing the validation function to the formik instance.
4. We’re passing the onSubmit function to the formik instance.
5. We’re using the getFieldProps function to get the field props for each field.
6. We’re destructuring the field props to get the field value and the field metadata.

Similar Posts