Files
Hangman-game-with-React/src/components/Hangman/PuzzleWord/AddLettersRegistered.js

24 lines
696 B
JavaScript

import alphabet from './alphabet'
const AddLettersRegistered = (lastLetterRegistered, setLastLetterRegistered) => {
const addLetterHistory = (event) => {
const currentKey = event.key
if (!lastLetterRegistered.includes(currentKey.toUpperCase()) && alphabet.includes(currentKey.toLowerCase())) {
const array = [...lastLetterRegistered, currentKey.toUpperCase()]
setLastLetterRegistered(array)
console.log(lastLetterRegistered)
}
window.removeEventListener('keyup', addLetterHistory)
}
window.addEventListener('keyup', addLetterHistory)
}
export default AddLettersRegistered