I am working on the Hangman game using react js, came across the error "TypeError: selectedWord.split is not a function" below is the code:
const Word = (selectedWord, correctLetters) => {
return (
<div className='word' id='word'>
{selectedWord.split().map((letter, i) =>{
return(
<span className='letter' key={i}>
${correctLetters.includes(letter)? letter : ''}
</span>
);
})}
</div>
);
}
CodePudding user response:
The way you are destructuring the props is incorrect, the correct syntax is:
const Word = ({ selectedWord, correctLetters }) => {
...
}
In your code, all of the props end up in the selectedWord
variable.