So I am making kind of like a hangman type of app where I scramble a sentence and a user has to guess the sentence. There are multiple input fields that is restricted to one letter. I want to make it possible so when the user types a letter the input would change to the next input field and so on until the last input field. If anyone can steer me in the right direction it would be greatly appreciated.
const InputGrid = ({sentence, key}) =>{
const [userInput, setUserInput] = useState('');
const [word, setWord] = useState('');
const [letters, setLetters] = useState([]);
console.log(userInput);
useEffect(() =>{
// let word = sentence.split(' ');
setWord(sentence);
setLetters(word.split(''));
}, [sentence, word]);
const handleChange = (event) =>{
setUserInput(event.currentTarget.value)
}
const successInput = {
background: 'green'
}
return(
<div>
{letters.map(letter =>{
return (<input
maxLength="1"
type="text"
key={key}
className="grid"
onChange={handleChange}
/>);
})}
</div>
)
};
export default InputGrid;