Created
September 11, 2018 19:47
-
-
Save yuritoledo/b001be4cbc6225186a9651111b20d493 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { withFormik, Form, Field } from 'formik' | |
| |
const MyFormWithFormik = withFormik({ | |
mapPropsToValues: () => ({ | |
email: '', | |
password: '', | |
address: { | |
/* outros campos */ | |
city: { | |
name: '', | |
/* outros campos */ | |
} | |
} | |
}), | |
handleSubmit: values => { | |
/** | |
* o values seria todos os valores do mapeados no mapValuesToProps, | |
* o segundo parametro são os métodos do formik, muito úteis | |
* Antes de rodar o handleSubmit, o formik já roda o método de | |
* validação dos dados, que posso escrever um novo artigo sobre | |
**/ | |
api.post(values) | |
} | |
}) | |
| |
const Form = () => ( | |
<Form> | |
<Field type="email" name="email" /> | |
<Field type="password" name="password" /> | |
<Field name="address.city.name" /> | |
<button type="submit" > | |
Submit | |
</button> | |
</Form> | |
) | |
| |
export default MyFormWithFormik(Form) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment