I am trying to make a little animation with an array where it kind of types out my name like in a command prompt. This is my first time using hooks in react so I'm kind of lost. I'd like to make it so that the interval stops at "Felipe Garcia Diaz" but instead of it stopping the interval just makes my text disappear and it continues to run in the background. What am i doing wrong exactly?
HooksExample.jsx
import React, {useState} from 'react';
import socket from './socket';
function Main(props) {
let introArray = ["_","F_", "Fe_", "Fel_", "Feli_", "Felip_", "Felipe_", "Felipe _", "Felipe G_", "Felipe Ga_", "Felipe Gar_", "Felipe Garc_", "Felipe Garci_", "Felipe Garcia_"];
let [myName, setName] = useState(introArray);
let [climber, setClimber] = useState(0);
let block = false;
if(block === false) {
let climbArray = () => {
setClimber(climber += 1);
if(climber === introArray.length) {
block = true;
console.log('dead');
}
console.log('live', climber);
}
setInterval(climbArray, 200);
}
return (
<React.Fragment>
<h1>{myName[climber]}</h1>
</React.Fragment>
);
}
export default Main;