I am using sqlite and I have created a db helper class. I am not getting the data from that class inside component, but if I am consoling inside db helper it is working right, but not in component. I am giving my code:-
Cartdb.js . (Helper class)
var SQLite = require('react-native-sqlite-storage')
db = SQLite.openDatabase('predefine.db', "1.0", "Predefine", -1);
class CartDB {
constructor(){
}
totalItems = 0;
checkCountOfProduct(){
query = "SELECT SUM(count) AS product_count FROM Predefinedcart";
db.transaction((tx) => {
tx.executeSql(query, [], (tx, results) => {
console.log(results.rows.item(0).product_count)
this.totalItems = results.rows.item(0).product_count;
return this.totalItems;
}, function (tx, error) {
console.log('SELECT error: ' + error.message);
});
})
}
}
export default new CartDB();
Code in Component:
import CartDB from '../../../library/CartDB';
class PredefinedLayout extends React.Component{
constructor(props){
super(props);
console.log(CartDB.checkCountOfProduct());
}
}
How can I get data here? Thanks in advance.