Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

UseState react variable dosen't apply correctly - Possible Unhandled Promise Rejection - Cannot read property data

$
0
0

I am completly new to ReactJS, Javascript and Typescript, but trying to be my best to improve,Sadly I am encountering a bug a can't find fix to :/

So, it seems that if a declare a const variable with React, and try to use it on a useEffect (to set a map variable in the GameStateBase, it dosen't work.

The thing is that if I dosen't use a variable and try to create the object inside the GameStateBase, it actualy works..

I need to have a reference to use it somewhere else in my code, so if anyone has an idea about where I did it bad, please help me :)

Explaination here

the error i'm getting (the map dosen't load)

Here is my code

const [scores, setScores] = useState<Array<scoreType>>([])// const maMap = new LSRace( {//  setScores: setScores// })// const [TheMap,setMaMap] = useState(new LSRace({//  setScores:setScores// }))const [maMap, setMaMap] = useState(new LSRace({    setScores: setScores}));useEffect(() => {const container = document.getElementById('viewport');//setMaMap(maMap) const gs = new GameStateBase({     map: maMap });// const gs = new GameStateBase({ //  map: new LSRace({//      setScores: setScores//  })// });console.log(maMap)const args: fiktiv_input_type = {    graphic_enabled: true,    input_enabled: true,    physic_enabled: true,    container: container,    multi: false,    gameState: gs}let fe = new FiktivEngine(args);

}, []);


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>