Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

26 строки
607 B

  1. import { useEffect, useRef } from 'react';
  2. /**
  3. * Store the last of some value. Tracked via a `Ref` only updating it
  4. * after the component renders.
  5. *
  6. * Helpful if you need to compare a prop value to it's previous value during render.
  7. *
  8. * ```ts
  9. * function Component(props) {
  10. * const lastProps = usePrevious(props)
  11. *
  12. * if (lastProps.foo !== props.foo)
  13. * resetValueFromProps(props.foo)
  14. * }
  15. * ```
  16. *
  17. * @param value the value to track
  18. */
  19. export default function usePrevious(value) {
  20. var ref = useRef(null);
  21. useEffect(function () {
  22. ref.current = value;
  23. });
  24. return ref.current;
  25. }