const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
let interval = null;
document.querySelector("h1").onmouseover = event => {
let iteration = 0;
clearInterval(interval);
interval = setInterval(() => {
event.target.innerText = event.target.innerText
.split("")
.map((letter, index) => {
if(index < iteration) {
return event.target.dataset.value[index];
}
return letters[Math.floor(Math.random() * 26)]
})
.join("");
if(iteration >= event.target.dataset.value.length){
clearInterval(interval);
}
iteration += 1 / 3;
}, 30);
}
This is js codepen i want to use this in my react app, How can i change this to react based code?
Copy pasted the code into JSX but it didnt work
Tried getting classname and added a classname in div but still it didnt work
2
Answers
This could maybe help you:
You can also use an onMouseOver event on H1 tag like this
Then, add a function handleMouseOver
However this will only work for single H1 tag as the function is only added to the particular jsx line, you can however re-use this function