-
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.
Allow using for UI management but not API mangement (#51)
- Loading branch information
1 parent
ccd6d6a
commit fff19f9
Showing
7 changed files
with
772 additions
and
142 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 |
---|---|---|
|
@@ -27,4 +27,4 @@ const config: Config.InitialOptions = { | |
] | ||
} | ||
|
||
export default config | ||
export default config |
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
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,14 +1,17 @@ | ||
import { useEffect, useRef } from "react" | ||
import { useEffect, useState } from "react" | ||
|
||
export function useDidMountEffect(fn: () => void, deps: any[]): void { | ||
const renderedOnce = useRef(false) | ||
/** | ||
* Like `useEffect`, but only runs after component has rendered at least once. | ||
*/ | ||
export function useEffectAfterMount(fn: () => void, deps: any[]): void { | ||
const [hasRendered, setHasRendered] = useState(false) | ||
|
||
useEffect(() => { | ||
if (renderedOnce.current) { | ||
if (hasRendered) { | ||
fn() | ||
} else { | ||
renderedOnce.current = true | ||
setHasRendered(true) | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, deps) | ||
}, [hasRendered, ...deps]) | ||
} |
Oops, something went wrong.