Skip to content

Instantly share code, notes, and snippets.

@arekbartnik
Forked from WebReflection/hooked-style.js
Created May 3, 2020 18:09
Show Gist options
  • Save arekbartnik/d7713ba699fa58529549b3ea49069f5d to your computer and use it in GitHub Desktop.
Save arekbartnik/d7713ba699fa58529549b3ea49069f5d to your computer and use it in GitHub Desktop.
A way to inject once per selector global styles, for more portable components.
import {define as hookedDefinition} from 'hooked-elements'; // or wicked-
import css from 'ustyler';
export const define = (selector, definition) => {
// let the library throw on duplicated selectors
const result = hookedDefinition(selector, definition);
// add styles for this selector
if (definition.style) css(definition.style);
// return the wicked/hooked magic 🌈
return result;
};
// export any other utility you like (i.e. useState and others)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment