Skip to content

Commit

Permalink
Fix rendering while updating in FormSpy and useFormState
Browse files Browse the repository at this point in the history
  • Loading branch information
zhujinxuan committed Dec 18, 2021
1 parent 3e0c032 commit 5c125b9
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/useFormState.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@ function useFormState<FormValues: FormValuesShape>({
form.subscribe((state) => {
initialState = state;
}, subscription)();
if (onChange) {
onChange(initialState);
}
return initialState;
},
);

React.useEffect(
() => {
if (onChange) {
onChange(state);
}
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[],
);
React.useEffect(
() =>
form.subscribe((newState) => {
Expand Down

0 comments on commit 5c125b9

Please sign in to comment.