Created
January 17, 2023 14:39
-
-
Save DevGW/b01a05790f46e23ca85e4fdf8bee3ca8 to your computer and use it in GitHub Desktop.
use-hook-form example #react-native
This file contains 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 {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