The only concepts you need to understand in StyleX:
1. Style Objects - apply them, merge them, use them conditionally whatever
2. Variable Objects - use them within styles
3. Themes - set values for variables on a UI sub-tree
That’s it. Seriously.
Built a Next + CLI example and even with some issues, it’s so much better already!
✅ Next 15 RC
✅ TurboPack dev+prod
✅ Next/Font
🚧 the @/ alias is broken
🚧 using styleX in dependencies has some issues
🚧 not all config options available yet
Curious what the recommended way to handle a hover state like this would be with StyleX, since they explicitly forbid styling based on parent hover.
Use JS to detect pointerEnter/pointerLeave on the parent and set some state that you use to change the text color?
V0.7.0 with CLI is finally out!
You can finally use StyleX within. Next app without opting out of SWC and TurboPack!
Also improvements to variables and fixes to bundler plugins.
Here’s a great introduction to Stylex from a creator that deserves more attention.
(Note: you need to set dev:true to inject classNames for debugging)
@JollyShopland
Here’s another guide to get started with a bare-bones Next+StyleX+open-props project from
@argyleink
The StyleX repo has an example app to copy as well.
We are aware of integration problems with certain frameworks, specially when using RSCs. We are working on making the experience better and would love some help!
Amazing, in-depth video explaining StyleX from
@DevSimplified
This is now the new canonical starting point for anyone diving into StyleX for the first time.
Shout out to the good folks at
@RockstarGames
for releasing the GTA 6 trailer a day early to make way for the launch.
And imitation really is the best form of flattery. They, too, are pre-announcing 2 years early!
CSS variables can now have types that are enforced by the browser.
StyleX now exports functions such as stylex.types.color() that can be used when defining variables.
📜 Quantifying the Impact of Styled Components on Server Response Times -
@drewml
Uses SpeedScope to analyze a CPU trace
Styled Components account for 47% of SSR time 😝
A good reason to move to a zero-runtime CSS-in-JS solution with build-time extraction, or Tailwind
CSS Cascade: The strategy used for choosing which CSS rule should win multiple rules apply. Aka Specificity Wars.
Inheritance: Child elements getting some styles from their parents. E.g. font-size, color, etc.
Composition: Merging styles to customise base component styles.
CSS is powerful and has amazing features. CSS layers is one of those amazing features.
Our job is to generate CSS that makes good use of that power while giving developers an interface that is vastly simpler, easier and more predictable.
@stylexjs
is so clever. It uses Cascade Layers to make CSS predictable, so last **always** wins. Bascially all CSS libraries struggle with this unless you manage cascade layers yourself, but StyleX generates cascade layers for you as a side effect
Huge thanks to NedJulius and QingqiShi for contributing the ESLint rule to “sort-keys” to help enforce consistent ordering of styles.
And a prettier plugin too!
@JoshWComeau
@NoriSte
You should probably look at Linaria based on your needs. It’s traditional styled components that are compiled static CSS. It supports all crazy selectors that we never will.
CSS Cascade: The strategy used for choosing which CSS rule should win multiple rules apply. Aka Specificity Wars.
Inheritance: Child elements getting some styles from their parents. E.g. font-size, color, etc.
Composition: Merging styles to customise base component styles.
The logo that wasn't, part 2.
This one is called "negative glow". I still think it looks quite cool, but it doesn't look so great in light-mode, `x` isn't easy to read for a lot of people and it requires "js" in the name.
@kenrickbeckett
@Meta
But now you won’t be able to set a different value for them with stylex.createTheme!
(We already infer styles as const in stylex.create())
Congrats🏆to the React OSS Awards winners!
💥Breakthrough of the Year: react-strict-dom (
@reactjs
)
💥The Most Exciting Use of Tech: React Native visionOS (
@callstackio
)
💥Productivity Booster:
@gluestack
💥Fun Side Project of the Year: React Server Components in Go (
@JLarky
)
@JoshWComeau
@username_ZAYDEK
@steida
This is the pattern we are planning to support. I.e “read” other elements but only style yourself. No styling at a distance.
Glad to see it’s a pattern being used with vanilla CSS already.
@nicknisi
@tailwindcss
That statement was for when not using utility functions like clsx.
Apart from the performance issues, clsx does solve most of the architectural limitations.
@thekxss
@t3dotgg
The problems it solves are usually more common with larger apps and teams, but StyleX works well for projects and teams of all sizes.
Use it if it feels good to your team.
@joshmedeski
@nicknisi
@tailwindcss
Clarification: In the docs, we’re talking architectural limitations on code organisation vs styling constraints which is what Adam is talking about and we agree with.
Also: our intent is not to criticize Tailwind, but highlight differences.
@thepredaytor
Ok! I misunderstood the intent of the original code.
Some modifications:
Skip the lines with stylex.include
And be explicit about the variant being used. This can be wrapped in a component to provide defaults instead.
@TheNoahHein
@dabit3
@CSSHooks
@tailwindcss
We only remove the “selectors” part of CSS. The styling part is identical to vanilla CSS. By design.
So please learn CSS first and you can reach for StyleX if you feel like you need it.
@JollyShopland
Our recommendation is to use just 3 lines as a reset. This is to maximise compatibility for components published to NPM.
For apps, bring your own reset.
@steida
That can be implemented as a sync tax transform on top of the StyleX compiler. StyleX avoids introducing custom API such as special props to JSX for a variety of reasons.
@thepredaytor
@adamwathan
Please put the media queries and pseudo classes within the value of properties.
Only pseudo elements are supported on the top-level (things that start with “::”)
@thepredaytor
Choose simplicity and don’t try to use fancy utility functions like CVA with StyleX. Here’s your code translated to StyleX APIs.
This is safer and faster. And we’re more likely to be able to detect if these styles were unused.