I am trying to use useState in React Native to store and display data but the array is displaying empty: Here's my data which I am trying to store:
Array [
Object {
"text": "Dhananjay",
"time": 1610528730258,
},
Object {
"text": "Abhey",
"time": 1610529549681,
},
Object {
"text": "Himanshu",
"time": 1610529566017,
},
]
Below is my code:
const [list, setList] = useState([]);
useEffect(() => {
const items = firebase.database().ref("userName");
items.on("value", datasnap => {
//console.log(Object.values(datasnap.val()));
console.log(list);
setList([...list, {
id: Object.values(datasnap.val())
}
]);
console.log(list);
})
console.log(list);
}, []);