dangerouslySetInnerHTML not working with Taillwind and React.js #7756
-
I am creating an app and fetching tailwind codes from an localhost file the file Code section looks like this |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 7 replies
-
Hi,
|
Beta Was this translation helpful? Give feedback.
-
dangerouslySetInnerHTML expects to be passed a string of HTML, not a string of JSX. The class attribute is used directly. You can't adjust the className property instead. Here is the stack overflow where I found the answer |
Beta Was this translation helpful? Give feedback.
-
Not sure if this solution would apply to buttons, but working with prismic what worked for me was using This way the code would be:
|
Beta Was this translation helpful? Give feedback.
-
Insert Tailwind css classes inside your css class. |
Beta Was this translation helpful? Give feedback.
-
This is way past due but in case someone in the future had the same problem read this. The accepted answer did not work for me so I did the following. Locate WHERE you are getting the HTML string fromIn my case it was in a file called Edit your
|
Beta Was this translation helpful? Give feedback.
-
When you try to run Vite or webpack does tree-shaking on the classes so if the classes are not in the project will be ignored. Therefore, you need to add all the classes you need to html string in safelist in the tailwind.config.js https://tailwindcss.com/docs/content-configuration#safelisting-classes
|
Beta Was this translation helpful? Give feedback.
Hi,
I had the same problem that I could fix by adding json file extension to
tailwind.config.js