i am trying to perform typewriting effect through hooks. consider the text given as hello world . it is rendering only hlo world . it is not adding element at index 1 to the currentText. here is my code
import React,{useEffect,useState,useRef} from 'react';
function Typewriter({text}) {
const index=useRef(0)
const [currentText,setCurrentText]=useState('');
useEffect(() => {
const timeOutId=setTimeout( () =>{
setCurrentText((value) => {
return value+text.charAt(index.current)
});
index.current +=1;
},1000);
return () =>{
clearTimeout(timeOutId);
}
},[currentText,text])
return (
<p>{currentText}</p>
)
}