You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

24 lines
706 B

  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;