useState is not working
can anyone tell me why in given below code is not working properly
let it return us "dark" but now i am trying to change dom by this value it is not working
in dom it is putting value of "translate-x-0" it should be "translate-x-[-93]"
28 Replies
whole component
Your setting localstoragetheme to a function
what that mean?
useState(()=>"hello") it will put usestate value to "hello" right?
Iirc, no
But test it and see
It might
it does
i know it
You have to use clsx or cn, to have conditional styles.
Ahh, so it does
oh why?
can't we do it will template string?
Because that's how it works
No
You don't
Yes you do
You're talking about the inline shorthand if in the string interp?
That will work perfectly fine
yeah
so where is problem?
${localStorageTheme === "dark" ? "translate-x-[-93%] " : "translate-x-0"}
This does not work with tailwind.It does because I do it in my projects lol