I’m using expo-sqlite to call a local database in react native. https://docs.expo.dev/versions/latest/sdk/sqlite/
I’ve tried to consume the JSON and have tried to use promises but each time I’m met with undefined when I attempt to render the data in my view. Below is my simplified layout.
How can I render this data from the sqlite successCallback?
repository.js
export const readTodos = () => {
db.transaction((tx) => {
tx.executeSql(
"SELECT * FROM todos",
null,
(_, { rows }) => JSON.stringify(rows),
(error) => console.log(ERROR_MESSAGE, error)
);
});
};
rows data
Array [
Object {
"id": 1,
"name": "homework",
},
Object {
"id": 2,
"name": "walk dog",
},
]
TodosScreen.js
import * as React from "react";
import { Text, StyleSheet } from "react-native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { readTodos } from "../storage/repository";
const Stack = createNativeStackNavigator();
function TodosScreen() {
var todoJSONdata = readTodos(); //
return <Text>I WANT TO RENDER ROW DATA HERE</Text>;
}
export default TodosScreen;