I have a state variable initialized like this:
const App = () => {
const [parameters, setParameters] = useState({
"shape": "circle",
"fontFamily": "",
"size": 500
});
//...
// which is here passed to a component
return(
<MyCanvas props={parameters} />
);
}
The parameters
array is used by another component that renders something on the canvas. I want that the parameters is on first load of the app, at runtime, to be what's currently defined in CSS, so I want to read that CSS property and init, in this case, the "fontFamily" field with what's written in CSS. Therefore want to read the @font-face {font-family: MyLocalFont;}
property from the CSS definition.
So generally: How would I read a value during runtime from a CSS for initializing the useState variable?
A compile-time solution would not meet my needs. Changes to the CSS styles can be made without re-deploying my widget, therefore I need to read the actual CSS property values during runtime upon initialization.