Skip to content

Commit

Permalink
Revert "☸️ fix #11910 watch reference update on each re-render (#12267)…
Browse files Browse the repository at this point in the history
…" (#12312)

This reverts commit b5863b4.
  • Loading branch information
bluebill1049 authored Oct 7, 2024
1 parent cb61669 commit 3bce0c8
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 33 deletions.
33 changes: 1 addition & 32 deletions src/__tests__/useForm/watch.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo } from 'react';
import React from 'react';
import {
act,
fireEvent,
Expand Down Expand Up @@ -552,35 +552,4 @@ describe('watch', () => {

screen.getByText('bill');
});

it('should update watch value with memo', () => {
function App() {
const { register, watch } = useForm({
defaultValues: {
firstName: '',
},
});

const firstName = useMemo(() => {
return watch('firstName');
}, [watch]);

return (
<form>
<p>{firstName}</p>
<input {...register('firstName')} />
</form>
);
}

render(<App />);

fireEvent.change(screen.getByRole('textbox'), {
target: {
value: 'bill',
},
});

screen.getByText('bill');
});
});
1 change: 0 additions & 1 deletion src/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ export function useForm<
}, [props.shouldUnregister, control]);

_formControl.current.formState = getProxyFormState(formState, control);
_formControl.current.watch = _formControl.current.watch.bind({});

return _formControl.current;
}

0 comments on commit 3bce0c8

Please sign in to comment.