Skip to content

[Answered] Functions always generate Dynamic styles. #347

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

You must be logged in to vote

I've considered this before and even investigated what it would take to implement something like this. I came to the conclusion that this was not viable, as there are a lot of edge-cases. The biggest being the inherent lack of Safety in typescript. (any allows you to bypass any type).

For the reason, there is an explicit warning against over-using dynamic styles. It's not something you should be using for "convenience". They should only be used when the style value is truly dynamic.

Instead, your should be doing something like this:

const padding = stylex.create({
  "0.5rem": { padding: "0.5rem" },
  "1rem": { padding: "1rem" },
});


// Usage
<div {...stylex.props(padding["0.5rem"])} />
<d…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by nmn
Comment options

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

nmn Jan 13, 2024
Collaborator

@aspizu
Comment options

@aspizu
Comment options

@nmn
Comment options

nmn Jan 15, 2024
Collaborator

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