@@ -14,37 +14,26 @@ The ``@realm/react`` library exposes realms in your application using
14
14
`React Context objects <https://reactjs.org/docs/context.html>`__ and Provider
15
15
components. You can access realms with React hooks.
16
16
17
- To open a local realm, create a Context with the realm's configuration. The
17
+ To configure and open a local realm, create a Context with the realm's configuration. The
18
18
Context exports a ``RealmProvider`` component that exposes a configured realm.
19
19
All child components of ``RealmProvider`` can access the realm using hooks.
20
20
21
21
To learn how to open a realm using Device Sync, refer to
22
22
:ref:`Open a Synced Realm <react-native-open-a-synced-realm>`.
23
23
24
- Create a Context Object with ``createRealmContext``
25
- ---------------------------------------------------
24
+ Create a Context Object
25
+ -----------------------
26
26
27
27
By passing a :js-sdk:`Configuration <Realm.html#~Configuration>` object to
28
- ``createRealmContext``, you can create a Context object that contains an open
28
+ ``createRealmContext() ``, you create a Context object that contains an open
29
29
realm and some hooks that give you access to the realm.
30
30
31
31
The following example creates and exports a Context object so that it can be
32
32
used elsewhere.
33
33
34
- .. literalinclude:: /examples/generated/react-native/ts/index.snippet.create-realm-context.ts
35
- :language: javascript
36
- :caption: Models/index.js
37
-
38
- Configure a Realm with ``<RealmProvider>``
39
- ------------------------------------------
40
-
41
- ``<RealmProvider>`` is a wrapper that exposes a Context with Realm Database to
42
- its child components. All child components inside ``<RealmProvider>`` have access
43
- to hooks that let you read, write, and update data. This is what a local-only
44
- realm wrapper might look like:
45
-
46
- .. literalinclude:: /examples/generated/react-native/ts/configure-realm-local.test.snippet.configure-realm.tsx
34
+ .. literalinclude:: /examples/generated/react-native/js/RealmConfig.snippet.create-realm-context.js
47
35
:language: javascript
36
+ :caption: RealmConfig.js
48
37
49
38
Open a Synced Realm
50
39
~~~~~~~~~~~~~~~~~~~
@@ -59,28 +48,39 @@ To create a realm that runs entirely in memory without being written to a file,
59
48
add ``inMemory: true`` to your :js-sdk:`Realm.Configuration
60
49
<Realm.html#~Configuration>` object:
61
50
62
- .. literalinclude:: /examples/generated/react-native/ts/index .snippet.in-memory-realm.ts
51
+ .. literalinclude:: /examples/generated/react-native/js/RealmConfig .snippet.in-memory-realm.js
63
52
:language: javascript
64
53
:emphasize-lines: 3
65
54
66
55
In-memory realms may use disk space if memory is running low, but files created
67
56
by an in-memory realm are deleted when you close the realm.
68
57
69
- Open One or More Realms
70
- ~~~~~~~~~~~~~~~~~~~~~~~
58
+ Encrypt a Realm
59
+ ~~~~~~~~~~~~~~~
60
+
61
+ To encrypt a realm database file on disk, refer to
62
+ :ref:`Encrypt a Realm <react-native-encrypt-a-realm>`.
63
+
64
+ Expose a Realm
65
+ --------------
66
+
67
+ ``<RealmProvider>`` is a wrapper that exposes a Context with Realm Database to
68
+ its child components. All child components inside ``<RealmProvider>`` have access
69
+ to hooks that let you read, write, and update data. This is what a local-only
70
+ realm wrapper might look like:
71
+
72
+ .. literalinclude:: /examples/generated/react-native/ts/configure-realm-local.test.snippet.configure-realm.tsx
73
+ :language: javascript
74
+
75
+ Expose More Than One Realm
76
+ --------------------------
71
77
72
78
You can open more than one realm at a time by creating additional Contexts and
73
79
``RealmProvider`` components.
74
80
75
81
.. literalinclude:: /examples/generated/react-native/ts/configure-realm-multiple.test.snippet.two-realm-contexts.tsx
76
82
:language: javascript
77
83
78
- Encrypt a Realm
79
- ~~~~~~~~~~~~~~~
80
-
81
- To encrypt a realm database file on disk, refer to
82
- :ref:`Encrypt a Realm <react-native-encrypt-a-realm>`.
83
-
84
84
Key Concept: Realm Files
85
85
------------------------
86
86
0 commit comments