-
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.
- Loading branch information
1 parent
e054d48
commit 8b8b162
Showing
3 changed files
with
36 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,9 @@ | ||
import { useEffect } from 'react' | ||
|
||
const useMount = (fn: () => void) => { | ||
useEffect(() => { | ||
fn?.() | ||
}, []) | ||
} | ||
|
||
export default useMount |
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,13 @@ | ||
import { useEffect } from 'react' | ||
import useLatest from '../useLatest' | ||
const useUnmount = (fn: () => void) => { | ||
const fnRef = useLatest(fn) | ||
useEffect( | ||
() => () => { | ||
fnRef.current() | ||
}, | ||
[] | ||
) | ||
} | ||
|
||
export default useUnmount |
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,14 @@ | ||
import { useEffect, useRef } from 'react' | ||
|
||
const useUnmountedRef = () => { | ||
const unmountedRef = useRef(false) | ||
useEffect(() => { | ||
unmountedRef.current = false | ||
return () => { | ||
unmountedRef.current = true | ||
} | ||
}, []) | ||
return unmountedRef | ||
} | ||
|
||
export default useUnmountedRef |