Realm only writes undefined objects on ReactNative

Hi, im trying to implement Realm in ReactNative but only writes undefined objects.

The code im using:

import React from ‘react’
import { SafeAreaView } from ‘react-native’
import Realm from ‘realm’;

export default function App() {

const TaskSchema = {
    name: "Task",
    properties: {
      _id: "int",
      name: "string",
      status: "string?",
    },
    primaryKey: "_id",
  };
  // Open a local realm file with a particular path & predefined Car schema

const realmDb = async () => {
    console.log('REALMDB');
  try {
    const realm = await Realm.open({
        path: "myrealm",
        schema: [TaskSchema],
      });

      let task1, task2;
    // realm.write(() => {
    //     task1 = realm.create('Task', {
    //     _id: 8,
    //     name: 'go grocery shopping',
    //     status: 'Open',
    //     });
    //     console.log(`created two tasks: ${task1.name}`);
    // });

    const tasks = realm.objects("Task");
    console.log(`The lists of tasks are: ${tasks.map((task) => task.name)}`);

    realm.close();

  } catch (err) {
    console.error("Failed to open the realm", err.message);
  }
}

realmDb()


return (
  <SafeAreaView>
  </SafeAreaView>
)

}

OUTPUT:
The lists of tasks are: ,

1 Like

Hi @Nedko,

Were you able to resolve this by chance as i have similar issues.

Thanks.