Change image on hover in react project with tailwindcss
Hi, I am doing a project with react and tailwindcss, and I am having some problems:
1 - I need to change a image inside a button when I hover the button, but I dont have any idea on how to do it.
2 - I need to make a button than onClick it opens a little menu with 3 other buttons, and I dont know how to do it with Tailwind too.
If someone have any ideia it would be very helpfull for me, thanks.
8 Replies
I am also trying to make a darkmode button but I keep getting this error when passing params to my useEffect "Argument of type 'string' is not assignable to parameter of type 'readonly unknown[]"
1) depends on the specifics of your requirement, but a way to implement it would be to have 2 images, one that is visible by default and hidden when the button is hovered, and the other image vice versa
2) This requires more than just tailwind but also js logic to handle the opening and closing and stuff. I recommend a headless library like headlessUI or radix which can provide you with unstyled components (such as https://headlessui.com/react/menu) to handle the logic
3) without context, I have no idea what the issue is lol
@corn flour I am going to test the things you send me just now. Thank you for your help. About the third problem I am going to send some prints here, but I deleted one parameter and it seems to be working, the problem is I just don't know why it works this way lol
this way it doesnt work and it pops the error I mentioned before
But if I delete changeMode from useEffect things start to work as it should
second param of useEffect is dep array, which takes in an array
you need to put
[changeMode]
insteadJust did it, it works, thank you very much
@corn flour Everything that you said worked, but I am trying to make the button using the library you sent and it's not working
well i wouldnt be able to tell what's not working from that lol