Newbie question

Hello, i am newbie in expo react native. I have a code working good, using a sqlite database.
The code to read data is:
db.transaction((tx) => {
tx.executeSql(query, , (tx, results) => {
if(results.rows.length == 0){
this.alertEmpty();
}
this.setState({
data: results.rows._array
});
});
});
}

My question is: how i can display using console.log the values inside “data”
Thanks.

In the same place that you call this.setState() you could call:

console.log(results.rows._array);

or possibly:

console.log(JSON.stringify(results.rows._array));

You will not be able to do something like this:

this.setState({ data: "something" });
console.log(this.state.data);

This is because the state is not updated immediately for performance reasons. See the following:

Another way to do it is like this:

this.setState(
  prevState => {
    data: results.rows._array;
  },
  () => console.log(this.state.data)
);

although the React documentation says this:

The second parameter to setState() is an optional callback function that will be executed once setState is completed and the component is re-rendered. Generally we recommend using componentDidUpdate() for such logic instead.

Hello,
Few days ago I try console.log(results.rows._array); but i got “undefined” in console output.
Same with:
this.setState(
prevState => {
data: results.rows._array;
},
() => console.log(this.state.data)
);