Skip to content

Instantly share code, notes, and snippets.

@geraldodev
Created April 25, 2018 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geraldodev/37eff01fad48f6d67ca45636355d77b3 to your computer and use it in GitHub Desktop.
Save geraldodev/37eff01fad48f6d67ca45636355d77b3 to your computer and use it in GitHub Desktop.
Implementation in reason of https://material-ui-next.com/customization/css-in-js/#other-html-element to allow creation of <noscript id="jss-insertion-point> for injecting material-ui at the start of the index.html and let others libraries css taking precedence over material-ui 's
type jssObj = {
.
"options": {. [@bs.set] "insertionPoint": Dom.element},
};
[@bs.module "jss"] external createJss : {.} => jssObj = "create";
[@bs.module "material-ui/styles"]
external jssPreset : unit => {.} = "jssPreset";
[@bs.module "material-ui/styles"]
external createGenerateClassName : unit => string = "createGenerateClassName";
let genClassName = createGenerateClassName();
let jss = createJss(jssPreset());
exception NoScriptIdNotFound(string);
let updateInsertionPoint = (noscriptId) => {
switch(ReactDOMRe._getElementById(noscriptId)) {
| Some(el) => jss##options##insertionPoint#=el
| None => raise(NoScriptIdNotFound("noscriptId " ++ noscriptId ++ " not found"))
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment