I'm making a math game, and I'd like the range of the operands to be updated after a certain amount of questions. I have this code to set the difficulty
const [difficulty, setDiff] = useState({rangeA:[1, 10], rangeB:[1, 10]});
function setDifficulty(op) {
let rangeA = [];
let rangeB = [];
if (question < 5) { //question state is incremented everytime the answer is correct, which triggers the next question
rangeA = [0, 100];
rangeB = [0, 10];
}
else if (question < 8) {
rangeA = [0, 100];
rangeB = [0, 100];
}
setDiff({...difficulty, rangeA, rangeB});
console.log(rangeB, difficulty.rangeB); // when question is 5, this logs [0, 100] [0, 10], but they should be the same value [0,100]
}
but the state doesn't update properly, what could be happening?