1.0.0 • Published 2 years ago

@rapid-platform/use-css-variables v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

React Hook useCssVariables

Maps an object of key value pairs onto a target HTML element ref as CSS Variables

This library has no dependencies.

function useCssVariables<S = Record<string, string | number | undefined>>(
  ref: React.MutableRefObject<any>,
  styles: S,
  deps?: React.DependencyList
): void;

Examples

Object of variables to add

const divRef = useRef<React.HTMLDivElement>();

// Values in object can be dynamic JS variables
const fontColor = "#3b3b3b";

const vars = {
  height: "10px",
  width: "30rem",
  color: fontColor,
};

useCssVariables(divRef, vars, [vars]);

return <div ref={divRef}>Content</div>;