3 ms·
Check out the format for an inline style: { background: "red", fontWeight: "bold" } It's just a Javascript mapping from strings to strings
by matchu 11y ago
Check out the format for an inline style:
{
background: "red",
fontWeight: "bold"
}
It's just a Javascript mapping from strings to strings. That's a very un-powerful language, and that's what React consumes.
Sure, you could generate this mapping with all sorts of arbitrary code, just like how you could generate CSS with all sorts of arbitrary code. But that doesn't make the style declaration itself any more powerful, much less an arbitrary executable.
- davidkpiano 11y agoThere is a difference, though. The above code is still executable in that it renders the proper styling via JS at run-time, rather than at "compile" time (i.e. when it is preprocessed).
- matchu 11y agoThat's true, but I don't feel like it's relevant. React's inline styles API satisfies the principle of least power: you can only pass to it a mapping from string keys to string/number values. It's possible that the input data might be compiled from some other more powerful format, and it's possible to argue that this compilation step is a violation of the principle of least power, but that feels like a separate issue. It's very possible to use inline styles without adding unnecessary power to the declaration language - heck, you could declare them in JSON and load them during the build step if you want. How you use inline styles is your decision.