I have a refresh icon in my React app that utilizes Material UI. I want the icon to spin for a second after it is clicked, but I am unsure of how to achieve this.
Despite attempting some solutions, none have been successful.
const useStyles = makeStyles((theme) => ({
refresh: {
marginTop: "20px",
cursor: "pointer",
margin: "auto",
animation: "spin 1s 1",
},
"@keyframes spin": {
"0%": {
transform: "translateY(-200%)",
},
"100%": {
transform: "translateY(0)",
},
},
}));
function Refresh() {
const [spin, setSpin] = React.useState(0);
const classes= useStyles();
const refreshCanvas = () => {
setSpin(1);
console.log("Refreshed");
};
return (
<AutorenewIcon
className={classes.refresh}
onClick={refreshCanvas}
onAnimationEnd={() => setSpin(0)}
spin={spin}
/>
)
}