i was trying to integrate Realm db to my project
Model File : export const CHAT_LIST_SCHEMA = { name: 'ImList', properties: { name: 'string', rid: 'string', lastMessage: 'string', time: 'string', },};
Code : init = async () => { try { Realm.open({ schema: CHAT_LIST_SCHEMA }).then((realm) => { let cachedData = realm.objects('ImList'); console.log('Cached Data', cachedData); if (cachedData === '') { console.log('called123'); this.setState({ data: cachedData }); } else { console.log('called'); const result = await RocketChat.getIMlist(); // API Call const data = await RocketChat.getRoomsList(result); // Filtering realm.write(() => { data.map((items) => { realm.create('ImList', { name: items.name, rid: items.rid, lastMessage: items.lastMessage, time: items.time, }); }); }); } }); } catch (error) { console.log(error); } };
But it shows I cant call await outside an async function, but I only need to get data from the API, if the DB is empty. What to do?