using useCallback for initAnswers function
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
b114f52b29
commit
3717240ce9
|
|
@ -1,4 +1,4 @@
|
||||||
import { createContext, useEffect, useState } from "react";
|
import { createContext, useEffect, useState, useCallback } from "react";
|
||||||
// import chantierAtmopshere from "../assets/sounds/chantier_1.mp3";
|
// import chantierAtmopshere from "../assets/sounds/chantier_1.mp3";
|
||||||
import GameAnswerExplanation from "../components/game/GameAnswerExplanation.jsx";
|
import GameAnswerExplanation from "../components/game/GameAnswerExplanation.jsx";
|
||||||
import { useUser } from "../hooks/useUser.jsx";
|
import { useUser } from "../hooks/useUser.jsx";
|
||||||
|
|
@ -32,13 +32,7 @@ export function GameContextProvider({ children }) {
|
||||||
const [isGameComplete, setIsGameComplete] = useState(false);
|
const [isGameComplete, setIsGameComplete] = useState(false);
|
||||||
|
|
||||||
// ##### INIT DATAS #####
|
// ##### INIT DATAS #####
|
||||||
useEffect(() => {
|
const initAnswers = useCallback(() => {
|
||||||
if (!contextGameDatas) return;
|
|
||||||
initAnswers();
|
|
||||||
setRemainingQuestionsAmount(contextGameDatas.gameObjects.length);
|
|
||||||
}, [contextGameDatas]);
|
|
||||||
|
|
||||||
function initAnswers() {
|
|
||||||
const answersArray = contextGameDatas.gameObjects.map((object, key) => {
|
const answersArray = contextGameDatas.gameObjects.map((object, key) => {
|
||||||
return {
|
return {
|
||||||
correctAnswer: object.attrs.behaviourType ? object.attrs.behaviourType : "unsafe",
|
correctAnswer: object.attrs.behaviourType ? object.attrs.behaviourType : "unsafe",
|
||||||
|
|
@ -47,7 +41,13 @@ export function GameContextProvider({ children }) {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
setAnswers(answersArray);
|
setAnswers(answersArray);
|
||||||
}
|
}, [contextGameDatas]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!contextGameDatas) return;
|
||||||
|
initAnswers();
|
||||||
|
setRemainingQuestionsAmount(contextGameDatas.gameObjects.length);
|
||||||
|
}, [contextGameDatas, initAnswers]);
|
||||||
|
|
||||||
function answerQuestion(answerKey, answer) {
|
function answerQuestion(answerKey, answer) {
|
||||||
if (!answer || answerKey === null) return;
|
if (!answer || answerKey === null) return;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user