mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-24 09:25:15 +00:00
24 lines
706 B
TypeScript
24 lines
706 B
TypeScript
import { EffectCallback, DependencyList } from 'react';
|
|
/**
|
|
* Runs an effect only when the dependencies have changed, skipping the
|
|
* initial "on mount" run. Caution, if the dependency list never changes,
|
|
* the effect is **never run**
|
|
*
|
|
* ```ts
|
|
* const ref = useRef<HTMLInput>(null);
|
|
*
|
|
* // focuses an element only if the focus changes, and not on mount
|
|
* useUpdateEffect(() => {
|
|
* const element = ref.current?.children[focusedIdx] as HTMLElement
|
|
*
|
|
* element?.focus()
|
|
*
|
|
* }, [focusedIndex])
|
|
* ```
|
|
* @param effect An effect to run on mount
|
|
*
|
|
* @category effects
|
|
*/
|
|
declare function useUpdateEffect(fn: EffectCallback, deps: DependencyList): void;
|
|
export default useUpdateEffect;
|