0
0
React Nativemobile~10 mins

Realm database in React Native - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import Realm in a React Native app.

React Native
import [1] from 'realm';
Drag options to blanks, or click blank then click option'
ARealm
BRealmReact
CRealmDB
Drealm
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase 'Realm' as the package name (import from 'Realm') which causes module not found error.
Trying to import from 'RealmDB' or other incorrect names.
2fill in blank
medium

Complete the code to define a Realm schema for a 'Task' object with a string 'name' property.

React Native
const TaskSchema = {
  name: 'Task',
  properties: {
    name: [1]
  }
};
Drag options to blanks, or click blank then click option'
Astring
BString
C'String'
D'string'
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted String or string which causes errors.
Using uppercase 'String' without quotes.
3fill in blank
hard

Fix the error in opening a Realm instance with the schema.

React Native
const realm = await Realm.open({
  schema: [[1]]
});
Drag options to blanks, or click blank then click option'
ATaskSchema
B[TaskSchema]
CTaskSchema()
D'TaskSchema'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the schema as a string.
Adding extra brackets causing nested arrays.
4fill in blank
hard

Fill in the blank to write a function that adds a new Task with a given name to Realm.

React Native
function addTask(realm, taskName) {
  realm.write(() => {
    realm.[1]('Task', { name: taskName });
  });
}
Drag options to blanks, or click blank then click option'
Ainsert
Bupdate
Ccreate
Dadd
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect method names like insert or add.
Passing a string literal instead of the variable for name.
5fill in blank
hard

Fill all three blanks to query all Task objects and filter those with name longer than 3 characters.

React Native
const tasks = realm.objects([1]).filtered([2] [3] 3);
Drag options to blanks, or click blank then click option'
A'Task'
Bname.length
C>
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using the schema name without quotes.
Filtering by 'name' instead of 'name.length'.
Using wrong comparison operators.