component.js 559 B

123456789101112131415
  1. import { styleHookSingleton } from './hook';
  2. /**
  3. * create a Component to add styles on demand
  4. * - styles are added when first instance is mounted
  5. * - styles are removed when the last instance is unmounted
  6. * - changing styles in runtime does nothing unless dynamic is set. But with multiple components that can lead to the undefined behavior
  7. */
  8. export const styleSingleton = () => {
  9. const useStyle = styleHookSingleton();
  10. const Sheet = ({ styles, dynamic }) => {
  11. useStyle(styles, dynamic);
  12. return null;
  13. };
  14. return Sheet;
  15. };