Understanding @emotion/babel-plugin's cssPropOptimization #2744
CodeWitchBella
started this conversation in
General
Replies: 1 comment
-
Interesting question! I think In my experience, the css prop is unlikely to cause performance issues unless you have a lot of elements or very frequent renders. Usually there will be other things in your application that are more of a performance bottleneck than the css prop. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Description:
I was trying to understand how to best take advantage of @emotion/babel-plugin's css prop optimization, how it works etc.
I create a simple playground on codesandbox (source) and discovered the following:
If you use css prop in its most simple form with object-style syntax you get a hoisted object (playground link)
It gets more complicated if you pass (possibly) dynamic values (playground link)
and (playground link)
My question is: which is better to use? Let's say this is in often-used component (like Button) and the static object contains many properties but we have a few dynamic ones (eg. color, borderColor and background from theme provided by react context). Is it better to split static values and dynamic values into separate objects so that static ones become strings, or should we keep that as one object and rely on
_css
function?My gut feeling would be to split it, but I would want to measure that before jumping to conclusions and I figured I would ask first before doing that :-)
Also, if there is a noticeable difference would it make sense for the babel plugin to transform from one to the other automatically?
Thank you for awesome library
Documentation links:
Beta Was this translation helpful? Give feedback.
All reactions