Complete the code to import Realm in a React Native app.
import [1] from 'realm';
The correct import is Realm with uppercase 'R' as it matches the default export name.
Complete the code to define a Realm schema for a 'Task' object with a string 'name' property.
const TaskSchema = {
name: 'Task',
properties: {
name: [1]
}
};Realm schema property types are strings like 'string' in quotes.
Fix the error in opening a Realm instance with the schema.
const realm = await Realm.open({ schema: [[1]] });
The schema option expects an array of schema objects, so [TaskSchema] is correct, but since the code already has brackets, just TaskSchema is needed inside.
Fill in the blank to write a function that adds a new Task with a given name to Realm.
function addTask(realm, taskName) {
realm.write(() => {
realm.[1]('Task', { name: taskName });
});
}Use realm.create to add a new object, and the task name is passed as taskName variable.
Fill all three blanks to query all Task objects and filter those with name longer than 3 characters.
const tasks = realm.objects([1]).filtered([2] [3] 3);
Query all 'Task' objects, then filter where the length of the name is greater than 3.