Skip to content

Commit

Permalink
feat: 🎸 Added useIsomorphicEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
prc5 committed Oct 16, 2022
1 parent c0ace17 commit a1fa7ff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/hooks/use-isomorphic-effect.hook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-disable react-hooks/exhaustive-deps */
import { useEffect, useLayoutEffect } from "react";

const isBrowser = typeof window !== "undefined";
const effect = isBrowser ? useEffect : useLayoutEffect;

export const useIsomorphicEffect = effect;
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
export * from "./hooks/use-force-update.hook";
export * from "./hooks/use-will-mount.hook";
export * from "./hooks/use-did-mount.hook";
export * from "./hooks/use-did-render.hook";
export * from "./hooks/use-did-change.hook";
export * from "./hooks/use-did-update.hook";
export * from "./hooks/use-will-unmount.hook";
export * from "./hooks/use-is-mounted.hook";
export * from "./hooks/use-isomorphic-effect.hook";

0 comments on commit a1fa7ff

Please sign in to comment.