<aside> ➡️ npm install @realm/react
</aside>
import Realm from 'realm';
import {useRealm, useQuery, useObject} from '@realm/react';
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',
};
}
기본적으로 세 함수 모두 같은 역할을 한다.