Skip to content

Store an object value instead of a string one #1818

Discussion options

You must be logged in to vote

For reference, here is what I finally did: I wrapped every input in a Controller. Sometimes the value is a string, sometimes it's something else.

Anyway, that means if I want to use an input with react-hook-forms, I always pass the component a control property, a name property and a rules property.

Here is an example with my LocationInput component (it may be what you want inside: a map, a dropdown... React hook form only handles the validation and the object value)

type InputLocationProps = {
   value: {lat: number, long: number;},
   onChange: ({lat: number, long: number}) => void
}

const InputLocation: ReactFC<InputLocationProps> = props => (
   <SomeMapComponent selectedLocation={{lat: 

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@bluebill1049
Comment options

Answer selected by maximelebastard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants