Reputation: 89
How to change the button icon on mouse hover with useEffect?
<Button
style={{ backgroundColor: "transparent" }}
type="primary"
icon={<img src={plusCart} />}
onClick={addToBasket}
/>
Upvotes: 0
Views: 1122
Reputation: 6582
You can change your code to something like this:
const [icon, setIcon] = useState(plusCart)
<Button
style={{ backgroundColor: "transparent" }}
type="primary"
icon={<img src={icon} />}
onClick={addToBasket}
onMouseEnter={() => setIcon(minusCart /**for example */)}
onMouseLeave={() => setIcon(plusIcon /**for example */)}
/>;
Upvotes: 1