With a single React app that hosts numerous customer websites which can be customized in various ways, I want to enable users to apply their own CSS code to their respective sites. Since users typically don't switch directly between websites, applying the custom styles at load time should suffice. However, the React code must run to determine the current site being accessed, as the server lacks information about the website's URL.
I came across a helpful resource detailing different approaches for styling in React (https://css-tricks.com/different-ways-to-write-css-in-react/), but none seem suitable for my scenario.
Would it be best for me to sidestep React and utilize vanilla JavaScript to generate a <style>
element and append it to the <head>
?
Edit: The CSS data will be in the form of a string retrieved from a GET request sent to the server, which might return something similar to this:
{
"name": "My Website",
"currency": "EUR",
"css": ".classone { display: none; } body { font-family: sans-serif; }",
"defaultCountry": "FR"
}