console.log(watch()) breaks controlled form #3295
-
|
Describe the bug To Reproduce See the sandbox, while console.log(watch()) is there you cannot type in the input, and if you try console logging within the Codesandbox link (Required)
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
|
you are mixing controlled input with uncontrolled. import * as React from "react";
import * as ReactDOM from "react-dom";
import { useForm } from "react-hook-form";
import "./styles.css";
const App = () => {
const { register, watch } = useForm();
// Comment out this line to fix form
console.log(watch());
return (
<div>
<label>First Name</label>
<input
name="firstName"
type="text"
ref={register}
pattern="[A-Za-z]+"
/>
</div>
);
}; |
Beta Was this translation helpful? Give feedback.
-
|
Maybe I'm not understanding the concepts correctly. In actual use, it's part of a bigger form which has some elements controlled (I want to limit the input so that only letters can appear, afaik the only way to do this is using state + onChange) and others that are uncontrolled. I reduced the form to only have one field so I could display the issue better, but maybe it's not useful. See below; what am I missing here? |
Beta Was this translation helpful? Give feedback.
-
|
why do you need |
Beta Was this translation helpful? Give feedback.
why do you need
setName?