Skip to content

Commit

Permalink
feat(hook/utils): add useIsomorphicLayoutEffect (#239)
Browse files Browse the repository at this point in the history
# Overview

<!--
    A clear and concise description of what this pr is about.
 -->

To distinguish whether it is a client or server environment from a hook
or component using `useEffect`

I will change the `useEffect` used in places where the client
environment and the server environment should be distinguished to the
`useIsomorphicLayoutEffect`.

## PR Checklist

- [x] I did below actions if need

1. I read the [Contributing
Guide](https://github.com/toss/slash/blob/main/.github/CONTRIBUTING.md)
2. I added documents and tests.

---------

Co-authored-by: Jonghyeon Ko <[email protected]>
  • Loading branch information
minsoo-web and manudeli authored Oct 20, 2023
1 parent 7f768a1 commit ad16119
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/react/src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { useIsChanged } from './useIsChanged'
export { useIsMounted } from './useIsMounted'
export { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect'
export { useKey } from './useKey'
export { usePrevious } from './usePrevious'
export { useIsChanged } from './useIsChanged'
export { useSetTimeout } from './useSetTimeout'
3 changes: 3 additions & 0 deletions packages/react/src/hooks/useIsomorphicLayoutEffect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { useEffect, useLayoutEffect } from 'react'
const isClient = typeof window !== 'undefined'
export const useIsomorphicLayoutEffect = isClient ? useLayoutEffect : useEffect
2 changes: 1 addition & 1 deletion packages/react/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { assert } from './assert'
export { hasResetKeysChanged } from './hasResetKeysChanged'
export { hashKey } from './hashKey'
export { assert } from './assert'

0 comments on commit ad16119

Please sign in to comment.