Dynamic bg color is not working has I accepted . #11189
-
Here I am attaching the code {color.map((ele) => <div className={ border w-10 h-10 bg-[${ele}] }>) } Here, Has I render the component the bg-[...] color render's a empty square but i suppose to get a colour in it . |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 6 replies
-
yes, I am also facing this issue |
Beta Was this translation helpful? Give feedback.
-
As per the documentation:
|
Beta Was this translation helpful? Give feedback.
-
After reading the tailwind documentation , ... //And now we can use this colour dynamically in the code, We can see the reflect in ui too. |
Beta Was this translation helpful? Give feedback.
-
How to fix this issue when the color is returned from API? |
Beta Was this translation helpful? Give feedback.
-
I think there is an issue with the rendering, so you need to first render it statically in your page while the page is rendering like You can ask the API provider to get the list of Colors from which he/she will send the color |
Beta Was this translation helpful? Give feedback.
-
in tailwind you cant use dynamic classes however you can use some dynamic color name like this: but in another way you can use style attribute for dynamic styles like this: |
Beta Was this translation helpful? Give feedback.
After reading the tailwind documentation ,
I founded one of the way by which we can use the classes dynamically.
For example let colour be green, red, yellow, purple and we want to use it like className =
bg-${color}-500
.while writing this directly we will not see any dynamic colour change in ui . So, to successfully use it we should write somewhere in the code for initialising the colours for example
...
//some where in the code
let colours = "bg-green-500 bg-red-500 bg-yellow-500 bg-purple-500"
//And now we can use this colour dynamically in the code, We can see the reflect in ui too.
//Here color can be green, red,yellow,purple
... className=
bg-${color}-500
...