I can't understand why this is happening I have added sample data manually and then I am pushing some more data later. Ultimately I want to display the data in a flatlist. Please help me, This is very important for my project. Thank yo Code:
class TasksScreen extends Component {
constructor(props) {
super(props);
this.state = {
tasks: [],
};
var tempTasks = [
{
key: 'abc',
val: 'abc',
},
];
var that = this;
var taskRef = database()
.ref('/Tasks/' + auth().currentUser.uid)
.on('value', dataSnapshot => {
var key = dataSnapshot.key;
console.log('UID KEY: ' + key);
dataSnapshot.forEach(childSnaps => {
var key = childSnaps.key;
console.log('TASKID KEY: ' + key);
childSnaps.forEach(taskData => {
var taskKey = taskData.key;
var taskVal = taskData.val();
console.log('taskData KEY: ' + taskKey);
console.log('taskData VAL: ' + taskVal);
console.log('taskData.val().title: ' + taskVal);
tempTasks.push({
taskTitle: 'title',
taskDescription: 'description',
taskDueTime: 'time',
taskDuedate: 'date',
});
});
});
console.log('tempTasks: ' + tempTasks);
that.setState({tasks: tempTasks});
console.log('STATE TASKS: ' + that.state.tasks);
});
}