-
Describe the bug To Reproduce Example 1
Example 2
Live Example Code import React, { Component } from 'react';
import { render } from 'react-dom';
import {useForm} from'react-hook-form'
const App = () => {
const {handleSubmit, register, getValues} = useForm();
return (
<form onChange={handleSubmit(data => console.log(data))}>
<label>Status</label>
<br/>
<select ref={register} name='status'>
<option>-</option>
<option>1</option>
<option>2</option>
</select>
<br/><br/>
<label>Details</label>
<br/>
{getValues().status === '1' && <input ref={register} name='details' />}
</form>
);
}
render(<App />, document.getElementById('root')); Desktop
|
Beta Was this translation helpful? Give feedback.
Answered by
pmaier983
Jul 7, 2020
Replies: 1 comment 1 reply
-
In this case I think it might help to use |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In this case I think it might help to use
useWatch
instead of getValues, and to analyze the formSubmit only on submit! Also take a look atunregister
for removing a property from your submit 😄