Dashboard sipadu mbip
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.

usePrevious.js 678B

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