Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
fix(useForm): elimiate useLayoutEffect warning in SSR
Browse files Browse the repository at this point in the history
  • Loading branch information
wellyshen committed Nov 7, 2020
1 parent e27c858 commit d40937d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/new-ants-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-cool-form": patch
---

fix(useForm): elimiate useLayoutEffect warning in SSR
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ import {
warn,
} from "./utils";

const useUniversalLayoutEffect =
typeof window === "undefined" ? useEffect : useLayoutEffect;

const isFieldElement = ({ tagName }: HTMLElement) =>
/INPUT|TEXTAREA|SELECT/.test(tagName);

Expand Down Expand Up @@ -576,7 +579,7 @@ const useForm = <V extends FormValues = FormValues>({
]
);

useLayoutEffect(() => {
useUniversalLayoutEffect(() => {
if (!formRef.current) {
warn(
'💡 react-cool-form: Don\'t forget to register your form via the "formRef".'
Expand Down

0 comments on commit d40937d

Please sign in to comment.