Currently working on React Native (iOS), with react-native-sqlite-storage. getUserData function is called by a component (ProfileView) and then it just logs it. If I try to log the array which is returned it works, but if I try to log the zero element of that same array it says that it's undefined. I have omitted okCallback and errorCallback as they just console.log the message sent to them. I also tried using objects and not arrays in getUserData, but it would just return undefined.
Database worker:
export function getUserData() {
var arr = [];
db.executeSql('SELECT * from userData;', [], results => {
let len = results.rows.length;
for(let i = 0; i < len; i++) {
arr.push(results.rows.item(i));
}
});
return arr;
}
class ProfileView extends React.Component {
constructor(props) {
super(props);
var test = getUserData();
console.log('not working', test[0])
console.log('working', test)
}
ProfileView:
class ProfileView extends React.Component {
constructor(props) {
super(props);
var test = getUserData();
console.log('not working', test[0])
console.log('working', test)
}
render() {
return (...);
}
}
Thanks in advance