I don’t know, although my app works fine in my local machine. when I deploy the in Netlify, the count stops working, so I saw in Console that handleClick works, yet the count always stays zero. only when you click very fast on the increment, you get 1 as the count. and again it becomes 0 for the next time. but this is not a problem if I use only one state for all characters, so just useState. what could be the prolem. thank you in advance for your answer.
import React, { useReducer } from 'react'
const initState = {
barbarian: 0,
archer: 0,
giant: 0,
goblin: 0,
wizard: 0
}
const actionTypes = {
increment: 'increment',
decrement: 'decrement'
}
function reducer(count, action) {
switch (action.type) {
case actionTypes.increment:
{
return {
...count,
[action.name]: count[action.name]++
}
}
case actionTypes.decrement:
{
return {
...count,
[action.name]: count[action.name] > 0 ? count[action.name]-- : 0
}
}
default:
return count
}
}
export default function Count({ name, id }) {
const [count, dispatch] = useReducer(reducer, initState)
function increment() {
setTimeout(() => {
dispatch({
type: actionTypes.increment,
id: id,
name: name
})
console.log(count[name])
console.log(name)
}, 500)
}
function decrement() {
setTimeout(() => {
dispatch({
type: actionTypes.decrement,
id: id,
name: name
})
}, 500)
}
return (
<div className='counter'>
<button onClick={decrement} className='bg-info'>-</button>
<p className='count'>{count[name]}</p>
<button onClick={increment} className='bg-success'>+</button>
</div>
)
}
```Preformatted text
its my deploy: