I have a series of inputs populated by an array of questions marks. I have another a second array that holds alpha numeric characters. If a user enters a character that matches from this second array then the first array gets updated accordingly. Doing it the react way means that I need to create a new array from the old one and set the state with the new array. I'm doing this in the code below, according to what I gather from the docs, react intends for it to be done. Everything works in the code below, except for the "letters" array not getting updated. Again, by looking at the docs, I don't see what I'm missing.
function inputChangeHandler(event) {
const incomingLetter = event.target.value;
const nextLetters = [...letters];
letters.forEach((letter,idx)=>{
if (letters_rec_of_truth[idx] === incomingLetter){
nextLetters[idx] = incomingLetter;
}
});
console.log("next letters is now "+nextLetters);
setLetters(nextLetters);
console.log("letters is now "+letters);
}