This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
my Goal: Is to create a simple effect that prints out a string one letter at a time.
example: string = "TEXT". it should print T E X T
Whats currently being printed is: T X T undefined
my code: ```
const [placeholder, setPlaceholder] = useState('');
const
string = 'TEXT',
index = useRef(0);
useEffect(() => {
function showChar() {
setPlaceholder(prev => prev string[index.current]);
console.log(index.current)
index.current ;
}
if (index.current < string.length) {
let addChar = setInterval(showChar, 500);
return () => clearInterval(addChar);
}
}, [placeholder]);
return (
<div>
{placeholder}
</div>
)
}
export default App;
Post Details
- Posted
- 2 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/react/comme...