Open fjcalzado opened 1 year ago
this is what you get if do as written
You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop).
Description: Thanks for this wonderful library, I love it! I am trying to better understand how
css
prop works under the hood forreact
in order to take the right decisions early and avoid performance bottleneck in complex applications.As stated in the documentation, it is better to define static css outside the component in order to serialize just once and get a constant reference for whole component lifecycle, like this:
But what happens when we have a depencency with the
theme
?First assumption: not-so-dynamic css. I mean,
theme
is unlikely to change frequently, so I assume we can still usecss
prop instead ofstyle
. Then, we have to pass a function right?Whether we collocate the css using
useTheme
hook:or we pass an inline callback:
or even if we extract that callback outside the component
none of the options will prevent css from being serialized on every render of the
Foo
component, is that correct? Are all the 3 approaches the same in terms of performance?Will a memoization based on
theme
add any benefit or is overkill or problematic withemotion
internals ? A simple utility like this might do the trick:but then I wonder why emotion does not memoize these callbacks by default?
Environment information:
@emotion/react
v11.10.5@emotion/babel-plugin
v11.10.5react
v17.0.2react-dom
17.0.2