Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

useUpdateEffect.d.ts 706 B

3 anni fa
1234567891011121314151617181920212223
  1. import { 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. */
  22. declare function useUpdateEffect(fn: EffectCallback, deps: DependencyList): void;
  23. export default useUpdateEffect;