UNPKG

706 BTypeScriptView Raw
1import { EffectCallback, DependencyList } from 'react';
2/**
3 * Runs an effect only when the dependencies have changed, skipping the
4 * initial "on mount" run. Caution, if the dependency list never changes,
5 * the effect is **never run**
6 *
7 * ```ts
8 * const ref = useRef<HTMLInput>(null);
9 *
10 * // focuses an element only if the focus changes, and not on mount
11 * useUpdateEffect(() => {
12 * const element = ref.current?.children[focusedIdx] as HTMLElement
13 *
14 * element?.focus()
15 *
16 * }, [focusedIndex])
17 * ```
18 * @param effect An effect to run on mount
19 *
20 * @category effects
21 */
22declare function useUpdateEffect(fn: EffectCallback, deps: DependencyList): void;
23export default useUpdateEffect;