hook.js 846 B

123456789101112131415161718192021222324252627
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.styleHookSingleton = void 0;
  4. var tslib_1 = require("tslib");
  5. var React = tslib_1.__importStar(require("react"));
  6. var singleton_1 = require("./singleton");
  7. /**
  8. * creates a hook to control style singleton
  9. * @see {@link styleSingleton} for a safer component version
  10. * @example
  11. * ```tsx
  12. * const useStyle = styleHookSingleton();
  13. * ///
  14. * useStyle('body { overflow: hidden}');
  15. */
  16. var styleHookSingleton = function () {
  17. var sheet = (0, singleton_1.stylesheetSingleton)();
  18. return function (styles, isDynamic) {
  19. React.useEffect(function () {
  20. sheet.add(styles);
  21. return function () {
  22. sheet.remove();
  23. };
  24. }, [styles && isDynamic]);
  25. };
  26. };
  27. exports.styleHookSingleton = styleHookSingleton;