Component - Realm database
This UI component shows how a React Native app uses Realm database to store and display a list of tasks. It lets users add new tasks and see them instantly on screen.
This UI component shows how a React Native app uses Realm database to store and display a list of tasks. It lets users add new tasks and see them instantly on screen.
App ├─ View (container) │ ├─ Text (title) │ ├─ FlatList (task list) │ │ └─ Text (task item) │ └─ Button (add task)
Task object with a string name and a boolean completed property?console.log(tasks.length);?
const realm = await Realm.open({schema: [TaskSchema]});
realm.write(() => {
realm.create('Task', {name: 'Buy milk', completed: false});
realm.create('Task', {name: 'Walk dog', completed: true});
});
const tasks = realm.objects('Task');
console.log(tasks.length);TaskSchema defines name as the primary key)
realm.write(() => {
realm.create('Task', {name: 'Read book', completed: false});
});
realm.write(() => {
realm.create('Task', {name: 'Read book', completed: true});
});name as primary key, creating an object with the same primary key without update flag causes error.name (primary key) without update flag, so it throws an error.completed status of a Task object named 'Laundry' to true. (Assume the Task schema defines name as the primary key) Which code snippet correctly performs this update in Realm?true as the third argument to create.Pass the test and this pattern moves unknown