-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hook): useUpdateEffect, useIsFirstRender hook 구현
- Loading branch information
1 parent
da851f9
commit 28a2a26
Showing
4 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@nf-team/react": minor | ||
--- | ||
|
||
feat(hook): useUpdateEffect, useIsFirstRender hook 구현 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
export { default as useActionKeyEvent } from './useActionKeyEvent'; | ||
export { default as useBoolean } from './useBoolean'; | ||
export { default as useDebounce } from './useDebounce'; | ||
export { default as useIsFirstRender } from './useIsFirstRender'; | ||
export { default as useIsMounted } from './useIsMounted'; | ||
export { default as useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect'; | ||
export { default as useLessThenScrollY } from './useLessThenScrollY'; | ||
export { default as useResizeViewportHeight } from './useResizeViewportHeight'; | ||
export { default as useThrottleCallback } from './useThrottleCallback'; | ||
export { default as useTimeout } from './useTimeout'; | ||
export { default as useUpdateEffect } from './useUpdateEffect'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { useRef } from 'react'; | ||
|
||
function useIsFirstRender(): boolean { | ||
const isFirst = useRef(true); | ||
|
||
if (isFirst.current) { | ||
isFirst.current = false; | ||
|
||
return true; | ||
} | ||
|
||
return isFirst.current; | ||
} | ||
|
||
export default useIsFirstRender; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { DependencyList, EffectCallback, useEffect } from 'react'; | ||
|
||
import useIsFirstRender from './useIsFirstRender'; | ||
|
||
function useUpdateEffect(effect: EffectCallback, deps?: DependencyList) { | ||
const isFirst = useIsFirstRender(); | ||
|
||
// eslint-disable-next-line consistent-return | ||
useEffect(() => { | ||
if (!isFirst) { | ||
return effect(); | ||
} | ||
}, deps); | ||
} | ||
|
||
export default useUpdateEffect; |