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.

useForceUpdate.js 899B

1234567891011121314151617181920212223242526272829303132
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.default = useForceUpdate;
  4. var _react = require("react");
  5. /**
  6. * Returns a function that triggers a component update. the hook equivalent to
  7. * `this.forceUpdate()` in a class component. In most cases using a state value directly
  8. * is preferable but may be required in some advanced usages of refs for interop or
  9. * when direct DOM manipulation is required.
  10. *
  11. * ```ts
  12. * const forceUpdate = useForceUpdate();
  13. *
  14. * const updateOnClick = useCallback(() => {
  15. * forceUpdate()
  16. * }, [forceUpdate])
  17. *
  18. * return <button type="button" onClick={updateOnClick}>Hi there</button>
  19. * ```
  20. */
  21. function useForceUpdate() {
  22. // The toggling state value is designed to defeat React optimizations for skipping
  23. var _useReducer = (0, _react.useReducer)(function (state) {
  24. return !state;
  25. }, false),
  26. dispatch = _useReducer[1];
  27. return dispatch;
  28. }