learn-morse-code/src/components/ChallengeWord.js

30 lines
837 B
JavaScript
Raw Normal View History

2020-01-09 10:06:38 +01:00
import React from "react"
2020-01-19 04:35:11 +01:00
export default React.memo(function ChallengeWord(props) {
2020-01-21 11:04:46 +01:00
let challengeWordClass= props.className
2020-01-21 11:04:46 +01:00
const word = props.word
const correctCharIndexes = props.correctCharIndexes
const incorrectCharIndex = props.incorrectCharIndex
let challengeLetters = word.split('')
let spannedWord = challengeLetters.map((letter,index) => {
let className = 'cLetter'
if (incorrectCharIndex === index) {
className = 'cLetter morseError'
} else if (correctCharIndexes.includes(index)) {
className = 'cLetter correct'
}
return (
<span key={index} className={className} id={"chal"+index}>{letter}</span>
)
})
2020-01-09 10:06:38 +01:00
return (
<div id="challengeWord" className={challengeWordClass}>{spannedWord}</div>
2020-01-09 10:06:38 +01:00
)
2020-01-19 04:35:11 +01:00
})