Docs Menu

Docs HomeDevelop ApplicationsAtlas Device SDK

UUID - React Native SDK

On this page

  • Usage
  • Example

New in version realm@10.5.0.

UUID (Universal Unique Identifier) is a 16-byte unique value. UUID is bundled with the Realm package as part of BSON (Realm.BSON.UUID).

You can use UUID as an unique identifier for objects. UUID is indexable, and you can use it as a primary key.

To define a property as a UUID, set its type to "uuid" in your object model. Create a Realm object within a write transaction. To set any unique identifier properties of your object to a random value, call new UUID(). Alternatively, pass a string to new UUID() to set the unique identifier property to a specific value.

In the following CreateProfileInput example, we create a Profile Realm.Object with a uuid type for the _id field.

The CreateProfileInput component does the following:

  • Gets access to the opened realm instance by calling the useRealm() hook.

  • Creates a name state variable
    called "name" that represents the name of the profile.
  • Creates a createProfile method that performs a write transaction. Within
    that write transaction, we create a Profile object with the name value of the "name" state variable and an _id value of a new UUID object.
  • Renders a TextInput component that allows the user to enter a name for
    the profile. When the user presses the "Create Profile" button, the createProfile method is called and creates a Profile object.
←  Mixed - React Native SDKEmbedded Objects - React Native SDK →

On this page