-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dashboard): Autofill payload with example in step preview
- Loading branch information
Showing
5 changed files
with
88 additions
and
17 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
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
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import debounce from 'lodash.debounce'; | ||
import { useEffect, useState, useMemo } from 'react'; | ||
|
||
type Callback = () => void; | ||
type DependencyList = ReadonlyArray<any>; | ||
|
||
/** | ||
* Custom hook that runs the callback immediately on the first render | ||
* and debounced on subsequent renders based on the dependency array. | ||
* | ||
* @param callback - The function to be executed. | ||
* @param deps - Dependency array for the effect. | ||
* @param delay - Delay in milliseconds for the debounced function. | ||
*/ | ||
function useDebouncedEffect(callback: Callback, delay: number, deps: DependencyList): void { | ||
const [hasRunOnFirstRender, setHasRunOnFirstRender] = useState(false); | ||
|
||
const debouncedCallback = useMemo(() => debounce(callback, delay), [callback, delay]); | ||
|
||
useEffect(() => { | ||
if (!hasRunOnFirstRender) { | ||
callback(); | ||
setHasRunOnFirstRender(true); | ||
} else { | ||
debouncedCallback(); | ||
} | ||
|
||
return () => { | ||
debouncedCallback.cancel(); | ||
}; | ||
}, deps); | ||
} | ||
|
||
export default useDebouncedEffect; |