Skip to content

Is there a preferred way to do component-level theming _without_ *.stylex.ts? (Answer: No -- not really) #849

Answered by nmn
zaydek asked this question in Q&A
Discussion options

You must be logged in to vote

TLDR; This is what I was going to suggest as the canonical way to do this pattern.

In the future, we might let you use stylex.defineVars in any file so you wouldn't need to put the variables in a separate file, but there are very good reasons to not allow that for now. (co-location of variable defs would make compilation and caching a lot harder)


However, I would suggest against this pattern in general. This is a pattern we tried as well and it leads to a couple of problems:

It causes CSS bloat.

The benefit of atomic CSS is that common styles can be shared across your entire app. If every component defines its own variables this becomes impossible and you CSS will start to grow linearly …

Replies: 3 comments 6 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@nmn
Comment options

nmn Jan 12, 2025
Collaborator

Answer selected by zaydek
@zaydek
Comment options

@nmn
Comment options

nmn Jan 13, 2025
Collaborator

Comment options

You must be logged in to vote
3 replies
@zaydek
Comment options

@necolas
Comment options

necolas Jan 15, 2025
Collaborator

@zaydek
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants