Skip to content

Instantly share code, notes, and snippets.

@DevGW
Created January 17, 2023 14:39
Show Gist options
  • Save DevGW/b01a05790f46e23ca85e4fdf8bee3ca8 to your computer and use it in GitHub Desktop.
Save DevGW/b01a05790f46e23ca85e4fdf8bee3ca8 to your computer and use it in GitHub Desktop.
use-hook-form example #react-native
import {useForm, Controller} from "react-hook-form"
const SearchForm = () => {
const {
control,
handleSubmit,
formState: {errors, isValid}
} = useForm({mode: 'onBlur'})
const onSubmit = data => console.log(data);
return(
<Fragment>
<Controller
control={control}
name="name"
render={({field: {onChange, value, onBlur}}) => (
<TextInput
placeholder="Enter your name here"
value={value}
onBlur={onBlur}
onChangeText={value => onChange(value)}
/>
)}
/>
<Button title='Submit' onPress={handleSubmit(onSubmit)}/>
<Button style={globalStyles.menuButton} mode="contained"
onPress={handleSubmit(onSubmit)}>
Press me
</Button>
</Fragment>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment