What i want to do is that i want to have the functionality of uncheck. For example: When i choose an odd the background of readonly input becomes yellow and when i click again it becomes white but it does not unselect the ratio of that odd. When background becomes yellow the e.target.value is added to the chosen state and when it becomes white again i could not find a way to remove the target value from state. I guess to understand better you might need to check the code in github(https://github.com/Elvaleryn/choosebet). Here is an image:img1. Note: i am well aware of .splice() method.
//state for selecting how much money user will put
const [betMoney, setBetMoney] = useState(3)
//state for the odd value
const [chosen, setChosen] = useState([1])
//basically a data base for games
const [games, setGames] = useState([])
//getting data from server
useEffect(() => {
gameService
.fetchGames()
.then(response => {
setGames(response.data)
})
}, [])
//to pick the chosen odd
const handleOptionChange = (game, option) => {
game[option] = !game[option]
setGames([...games])
}
const handleMoneyChange = (event) => {
setBetMoney(event.target.value)
}
//when odd is chosen it activates the handle option change to apply background color
const chooseOdd = (e, person, option) => {
//when odd is chosen it activates the handle option change to apply background color
handleOptionChange(person, option)
const index = e.target.value
setChosen(chosen.concat(index))
}
const ratioTotal = chosen.reduce((a, b) => a * b)
const result = parseFloat(ratioTotal * betMoney).toFixed(2)