I am new to working with React Native and I am facing an issue in my main component where I am trying to execute a database query and retrieve the data. However, when I run it, the console logs 'undefined'. Can anyone help me solve this problem? Thank you.
Here is my main component:
const fetchData = async () => {
let queryselect = 'SELECT * FROM tbl_messages ';
var result = await selectData(queryselect);
if (result === false) {
console.log('no data');
} else {
console.log(result);
}
}
In my database component:
var db = openDatabase({ name: 'message.db', createFromLocation: 1 });
db.transaction(tx => {
tx.executeSql(
query,
[],
(tx, results) => {
var len = results.rows.length;
if (len === 0) {
console.log('no records found');
return false;
} else {
var temp = [];
for (let i = 0; i < results.rows.length; ++i) {
temp.push(results.rows.item(i));
}
return temp;
}
}
);
});
}