You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We usually write styles inside styled, but in the render area of the function component we need to flexibly assemble these styled components, and there is no selector for inline styles, babel plugin isn't my choice since I'm using swc to compile, so here is my solution, and I wanna discuss with people what's the PROS and CONS of this approach.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
We usually write styles inside styled, but in the render area of the function component we need to flexibly assemble these styled components, and there is no selector for inline styles, babel plugin isn't my choice since I'm using swc to compile, so here is my solution, and I wanna discuss with people what's the PROS and CONS of this approach.
! [image] (https://github.com/user-attachments/assets/9589f96d-f1ec-4291-ba61-947cbd32d860) DOM appearence
PROS:
css()
utility.${Comp}
will resolved as.sc-gnpbhQ
(a generated classname corresponding to your element)<style>
element will alongside with lifecycle (mount, updates, unmount)CONS:
<Parent/>
and Parent has a style element, there will be 20 same<style>
in DOMUPDATES:
I've achieved a way to make style scoped, here is the usage:
! [image] (https://github.com/user-attachments/assets/22fa41cf-63dc-4ee1-9f3b-b0b1a4b23436)
And the DOM looks like this:
! [image] (https://github.com/user-attachments/assets/63fda4a3-bec1-49b0-a929-6dc13b71d587)
What does style fn do?
It renders a
style
html tag with an unique id, and select the root element in stylesheet, so that style will only effect under the root jsx element.I'm trying to take it a step further, so far so good.
Or put style below jsx, more vue style
Beta Was this translation helpful? Give feedback.
All reactions