MCPcopy Create free account
hub / github.com/react-hook-form/react-hook-form / SetValueAsyncStrictMode

Function SetValueAsyncStrictMode

app/src/setValueStrictMode.tsx:4–50  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2import { useForm, Controller } from 'react-hook-form';
3
4const SetValueAsyncStrictMode = () => {
5 const state = React.useRef(new Set());
6 const [, update] = React.useState({});
7 const { register, setValue, control } = useForm<{
8 firstName: string;
9 }>();
10
11 useEffect(() => {
12 setTimeout(() => {
13 setValue('firstName', 'A');
14 }, 10);
15
16 setTimeout(() => {
17 setValue('firstName', 'B', { shouldDirty: true });
18 }, 20);
19
20 setTimeout(() => {
21 setValue('firstName', 'C', { shouldTouch: true });
22 }, 30);
23
24 setTimeout(() => {
25 setValue('firstName', 'D', { shouldValidate: true });
26 }, 40);
27 }, [register, setValue]);
28
29 return (
30 <React.StrictMode>
31 <form>
32 <Controller
33 defaultValue={'test'}
34 control={control}
35 render={({ field }) => {
36 state.current.add(field.value);
37 return <input id={'input'} {...field} />;
38 }}
39 name={'firstName'}
40 />
41
42 <button id="submit" type={'button'} onClick={() => update({})}>
43 Submit
44 </button>
45
46 <p id="result">{JSON.stringify([...state.current])}</p>
47 </form>
48 </React.StrictMode>
49 );
50};
51
52export default SetValueAsyncStrictMode;

Callers

nothing calls this directly

Calls 3

useFormFunction · 0.85
setValueFunction · 0.85
updateFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…