'React native useState not working with real time firebase
inside getRoomData function setRoomInfo not working? How can i fix it? I can't see data from joinGame.
import React,{useState,useEffect} from 'react';
const [roomInfo,setRoomInfo] = useState([]);
function getRoomData(){
const roomID = room;
database()
.ref(`rooms/${roomID}/`)
.on('value', snapshot => {
const list = snapshot.val();
if(list!=null){
console.log("getRoom:"+list.roomid)
const r = list;
setRoomInfo(r);
}
});
}
function joinGame(){
console.log(roomInfo);
}
useEffect(()=>{
getRoomData();
},[])
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
