Dashboard sipadu mbip
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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. }