-
Notifications
You must be signed in to change notification settings - Fork 48.6k
Use cssText
instead of setting css properties individually
#5397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
cssText
instead of setting css properties explicitlycssText
instead of setting css properties individually
My gut feeling is that this is going in the wrong direction and that it makes no sense to serialize CSS just so that it can be reparsed by the browser (just as we're moving from innerHTML to createElement). This will become even more true as CSS values become more structured in the DOM which there are plans for. But if this really seems better then I'm not really opposed. I think at least some people are relying on the fact that we don't reset inline styles that you don't specify in React though… (e.g., for animations). |
I found this page since:
We want to render inline CSS on server-side but the object representation does not solve By the way it there anything like |
Hey! I need to be able to set inline styles as
At least, are there any workaround? |
As noted by @sophiebits we most likely won’t be doing this. @Ta4i For your use case, I think you can create a DOM element, try to assign different |
Based on the discussion in: #5030 (comment)
Currently, we diff css properties and imperatively set individual properties for each value that differs from the previous render. We've long claimed that "performance" was the reason, but the benchmarks don't seem to support this claim. For instance, consider Ben's perf test (http://jsperf.com/style-vs-csstext-vs-setattribute/8 (from #929). Realistically, there are cases where one technique is faster than the other, and vice versa. It's probably a wash.
But using
cssText
has several advantages over our current approach. Most notably, it solves correctness issues related to the various css shorthand properties (as noted in #5030). It also cleanly solves vendor prefixing, and a variety of other edge cases. Plus, as an added bonus, it means that the React core is doing less work and is therefore simpler/cleaner/moreMaintainable.The text was updated successfully, but these errors were encountered: