설치

<aside> ➡️ npm install @realm/react

</aside>

사용

import Realm from 'realm';
import {useRealm, useQuery, useObject} from '@realm/react';

Schema

import Realm, { ObjectSchema } from "realm";

export class ToDo extends Realm.Object<ToDo> {
    id!: string;
    text!: string;
    complete!: boolean;
    completeDate?: string;
    timestamp: number = Math.round(new Date().getTime() / 1000);
    
    static schema: ObjectSchema = {
      name: 'Todo',
      properties: {
        id: 'string',
        text: 'string',
        complete: { type: 'bool', default: false },
        completeDate: 'string?', //{ type: 'string', optional: true }
        timestamp: {
          type: 'int',
          default: () => Math.round(new Date().getTime() / 1000),
        },
      },
      primaryKey: 'id',
    };
  }

Realm.open() 과 new Realm() 그리고 useRealm()

기본적으로 세 함수 모두 같은 역할을 한다.