Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update react-hooks-forms.md #437

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 21 additions & 18 deletions docs/3.1.x/react-hooks-forms.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import React from 'react';
import { useForm, Controller } from 'react-hook-form';

function FormHookExample() {
const { control, handleSubmit, errors } = useForm();
const onSubmit = (data) => {
const { control, handleSubmit, formState: {errors} } = useForm();

const onSubmit = (data: any) => {
console.log('submiting with ', data);
};
return (
Expand All @@ -29,16 +30,16 @@ function FormHookExample() {
<FormControl.Label>First Name</FormControl.Label>
<Controller
control={control}
render={({ onChange, onBlur, value }) => (
render={({field: {onChange, onBlur, value}}) => (
<Input
onBlur={onBlur}
placeholder="John"
onChangeText={(val) => onChange(val)}
onChangeText={val => onChange(val)}
value={value}
/>
)}
name="firstName"
rules={{ required: 'Field is required', minLength: 3 }}
rules={{required: 'Field is required', minLength: 3}}
defaultValue=""
/>
<FormControl.ErrorMessage>
Expand All @@ -49,11 +50,11 @@ function FormHookExample() {
<FormControl.Label>Last Name</FormControl.Label>
<Controller
control={control}
render={({ onChange, onBlur, value }) => (
render={({field: {onChange, onBlur, value}}) => (
<Input
onBlur={onBlur}
placeholder="Doe"
onChangeText={(val) => onChange(val)}
onChangeText={val => onChange(val)}
value={value}
/>
)}
Expand All @@ -68,22 +69,24 @@ function FormHookExample() {
<FormControl.Label>Age</FormControl.Label>
<Controller
control={control}
render={({ onChange, onBlur, value }) => (
render={({field: {onChange, onBlur, value}}) => (
<Input
onBlur={onBlur}
placeholder="24"
onChangeText={(val) => onChange(val)}
onChangeText={val => onChange(val)}
value={value}
/>
)}
name="age"
rules={{ min: 18, required: 'Age is required' }}
rules={{min: 18, required: 'Age is required'}}
defaultValue=""
/>
<FormControl.ErrorMessage>
{errors.age?.type === 'required'
? errors.age?.message
: errors.age?.type === 'min' ?? 'Under age'}
: errors.age?.type == 'min'
? 'Under age'
: null}
</FormControl.ErrorMessage>
</FormControl>
<Button onPress={handleSubmit(onSubmit)} colorScheme="pink">
Expand Down Expand Up @@ -118,7 +121,7 @@ import React from 'react';
import { useForm, Controller } from 'react-hook-form';

function FormHookCheckboxExample() {
const { control, handleSubmit, errors } = useForm();
const { control, handleSubmit, formState: {errors} } = useForm();
const onSubmit = (data) => {
console.log('submiting with ', data);
};
Expand Down Expand Up @@ -230,7 +233,7 @@ import React from 'react';
import { useForm, Controller } from 'react-hook-form';

function FormHookSelectExample() {
const { control, handleSubmit, errors } = useForm();
const { control, handleSubmit, formState: {errors} } = useForm();
const onSubmit = (data) => {
console.log('submiting with ', data);
};
Expand Down Expand Up @@ -298,7 +301,7 @@ import React from 'react';
import { useForm, Controller } from 'react-hook-form';

function FormHookSliderExample() {
const { control, handleSubmit, errors } = useForm();
const { control, handleSubmit, formState: {errors} } = useForm();
const onSubmit = (data) => {
console.log('submiting with ', data);
};
Expand Down Expand Up @@ -353,7 +356,7 @@ import React from 'react';
import { useForm, Controller } from 'react-hook-form';

function FormHookTextareaExample() {
const { control, handleSubmit, errors } = useForm();
const { control, handleSubmit, formState: {errors} } = useForm();
const onSubmit = (data) => {
console.log('submiting with ', data);
};
Expand Down Expand Up @@ -407,7 +410,7 @@ import React from 'react';
import { useForm, Controller } from 'react-hook-form';

function FormHookSwitchExample() {
const { control, handleSubmit, errors } = useForm();
const { control, handleSubmit, formState: {errors} } = useForm();
const onSubmit = (data) => {
console.log('submiting with ', data);
};
Expand Down Expand Up @@ -464,7 +467,7 @@ import React from 'react';
import { useForm, Controller } from 'react-hook-form';

function FormHookNumberInputExample() {
const { control, handleSubmit, errors } = useForm();
const { control, handleSubmit, formState: {errors} } = useForm();
const onSubmit = (data) => {
console.log('submiting with ', data);
};
Expand Down Expand Up @@ -524,7 +527,7 @@ import React from 'react';
import { useForm, Controller } from 'react-hook-form';

function FormHookPinInputExample() {
const { control, handleSubmit, errors } = useForm();
const { control, handleSubmit, formState: {errors} } = useForm();
const onSubmit = (data) => {
console.log('submiting with ', data);
};
Expand Down