D
D
Denis Sokolov2021-02-17 18:07:47
React
Denis Sokolov, 2021-02-17 18:07:47

Why is REact not rendering state?

const getStopHandler = () => {
        const array = enemy.cards

        for (let i = 0; i < player.cards.length - 1; i++) {
            const card = cards[getRandomInt(cards.length)]
            array.push(card)

            console.log(array)
        }

        const countCheck = array.reduce((accumulator, currentValue) => {
            return accumulator + currentValue.count
        }, 0)

        setEnemy({
            count: countCheck,
            cards: array
        })

        console.log(enemy, countCheck)

        setTimeout(() => {
            console.log(enemy)
            if (player.count > 21 && enemy.count < 22) {
                setActive({
                    active: true,
                    text: 'ПРОИГРАЛИ'
                })
            } else if (player.count === enemy.count) {
                setActive({
                    active: true,
                    text: 'НИЧЬЯ'
                })
            } else if (player.count > enemy.count && player.count < 22) {
                setActive({
                    active: true,
                    text: 'ВЫИГРАЛИ'
                })
                console.log('player.count > enemy.count && player.count < 22', player.count > enemy.count && player.count < 22)
            } else if (player.count < enemy.count && enemy.count < 22) {
                setActive({
                    active: true,
                    text: 'ПРОИГРАЛИ'
                })
            } else if (enemy.count === player.count && enemy.count > 21) {
                setActive({
                    active: true,
                    text: 'ПРОИГРАЛИ'
                })
            } else {
                setActive({
                    active: true,
                    text: 'ПРОИГРАЛИ'
                })
            }
        }, 1000)
    }


Why where setEnemy only changes cards but does not change count although countCheck reads everything as it should

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question