How to define dynamic variable #206
-
How can I write variables that come dynamically, for example, from an API? I want to create a variable using defineVars, but I don't know how to do that.
Normally, I can set CSS variables inside the style tag in my application root. |
Beta Was this translation helpful? Give feedback.
Answered by
nmn
Dec 18, 2023
Replies: 1 comment
-
Step 1Define default values for variables using Step 2Use const styles = stylex.create({
dynamicTheme: (themeFromAPI) => ({
[colors.accent]: themeFromAPI.accent,
}),
});
// Somewhere near the top of the app:
<html {...stylex.props(styles.dynamicTheme(themeFromAPI))}>
{children}
</html> NOTE:
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
nmn
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Step 1
Define default values for variables using
defineVars
. These default values cannot be dynamic. These are the default values.Step 2
Use
stylex.create
to set values for variables dynamically:NOTE:
createTheme
if this is a common use-case