|
4 | 4 | Connect to an Atlas App Services App - React Native SDK
|
5 | 5 | =======================================================
|
6 | 6 |
|
| 7 | +.. contents:: On this page |
| 8 | + :local: |
| 9 | + :backlinks: none |
| 10 | + :depth: 2 |
| 11 | + :class: singlecol |
| 12 | + |
7 | 13 | Overview
|
8 | 14 | --------
|
9 | 15 |
|
10 | 16 | The App client is the interface to the App Services
|
11 | 17 | backend. It provides access to the :ref:`authentication functionality
|
12 |
| -<react-native-authenticate-users>`, :ref:`functions <react-native-call-a-function>`, and |
13 |
| -:ref:`sync management <react-native-realm-sync>`. |
14 |
| - |
15 |
| - |
16 |
| -.. _react-native-access-the-app-client: |
17 |
| - |
18 |
| -Access the App Client |
19 |
| ---------------------- |
20 |
| - |
21 |
| -Pass the Realm App ID for your App, which you can :ref:`find in the Realm UI <find-your-app-id>`. |
22 |
| - |
23 |
| -.. tabs-realm-languages:: |
24 |
| - |
25 |
| - .. tab:: |
26 |
| - :tabid: typescript |
27 |
| - |
28 |
| - .. code-block:: typescript |
29 |
| - |
30 |
| - const id = "<Your App ID>"; // replace this with your App ID |
| 18 | +<react-native-authenticate-users>`, :ref:`Atlas Functions <react-native-call-a-function>`, |
| 19 | +and :ref:`Atlas Device Sync <react-native-realm-sync>`. |
31 | 20 |
|
32 |
| - .. tab:: |
33 |
| - :tabid: javascript |
| 21 | +Before You Begin |
| 22 | +---------------- |
34 | 23 |
|
35 |
| - .. code-block:: javascript |
36 |
| - |
37 |
| - const id = "<Your App ID>"; // replace this with your App ID |
| 24 | +#. :ref:`Create an App Services App <create-a-realm-app>` |
| 25 | +#. :ref:`Get Your App ID <find-your-app-id>` |
38 | 26 |
|
39 | 27 | .. _react-native-app-client-configuration:
|
| 28 | +.. _react-native-access-the-app-client: |
40 | 29 |
|
41 |
| -Configuration |
42 |
| -------------- |
43 |
| - |
44 |
| -To set up your App client, pass a configuration object to an instance |
45 |
| -of ``Realm.App``. |
46 |
| - |
47 |
| -.. tabs-realm-languages:: |
48 |
| - |
49 |
| - .. tab:: |
50 |
| - :tabid: typescript |
51 |
| - |
52 |
| - .. code-block:: typescript |
53 |
| - |
54 |
| - const config = { |
55 |
| - id, |
56 |
| - }; |
57 |
| - const app = new Realm.App(config); |
58 |
| - |
59 |
| - .. tab:: |
60 |
| - :tabid: javascript |
| 30 | +Configure the App Client |
| 31 | +------------------------ |
61 | 32 |
|
62 |
| - .. code-block:: javascript |
| 33 | +To set up your App client, pass the App ID string |
| 34 | +to the ``id`` prop of the ``AppProvider``. |
| 35 | +Wrap any components that need to access the App with the ``AppProvider``. |
63 | 36 |
|
64 |
| - const config = { |
65 |
| - id, |
66 |
| - }; |
67 |
| - const app = new Realm.App(config); |
68 | 37 |
|
69 |
| -.. note:: |
70 |
| - |
71 |
| - ``id`` is a required field of the application configuration object. To see the full list of fields for the configuration object that ``Realm.App`` accepts as a parameter, view the :js-sdk:`App Configuration Type Definitions <Realm.App.html#~AppConfiguration>`. |
| 38 | +.. literalinclude:: /examples/generated/react-native/ts/app-provider.test.snippet.app-provider.tsx |
| 39 | + :language: typescript |
72 | 40 |
|
73 | 41 | .. _react-native-app-retrieve-client:
|
74 | 42 |
|
75 | 43 | Retrieve an Instance of the App Client
|
76 | 44 | --------------------------------------
|
77 | 45 |
|
78 |
| -To retrieve an instance of the App Client from anywhere in your application, call :js-sdk:`Realm.App.getApp() <Realm.App.html#getApp>` and pass in your ``App ID``. |
79 |
| - |
80 |
| -.. tabs-realm-languages:: |
81 |
| - |
82 |
| - .. tab:: |
83 |
| - :tabid: typescript |
| 46 | +All components wrapped within an ``AppProvider`` can access the :js-sdk:`App <Realm.App.html>` |
| 47 | +client with the ``useApp()`` hook. Using the App, you can authenticate users |
| 48 | +and access App Services. |
84 | 49 |
|
85 |
| - .. code-block:: typescript |
| 50 | +.. literalinclude:: /examples/generated/react-native/ts/use-app.test.snippet.use-app.tsx |
| 51 | + :language: typescript |
86 | 52 |
|
87 |
| - const app = Realm.App.getApp("<Your App ID>"); // replace this with your App ID |
| 53 | +.. _react-native-retrieve-client-outside-provider: |
88 | 54 |
|
89 |
| - .. tab:: |
90 |
| - :tabid: javascript |
| 55 | +Retrieve App Outside the App Provider |
| 56 | +------------------------------------- |
91 | 57 |
|
92 |
| - .. code-block:: javascript |
| 58 | +To retrieve an instance of the App Client from anywhere in your application, |
| 59 | +instantiate a new instance of :js-sdk:`Realm.App() <Realm.App.html>` |
| 60 | +from the ``realm`` package, then pass in your ``App ID``. |
93 | 61 |
|
94 |
| - const app = Realm.App.getApp("<Your App ID>"); // replace this with your App ID |
| 62 | +.. code-block:: typescript |
95 | 63 |
|
| 64 | + import Realm from 'realm'; |
96 | 65 |
|
97 |
| - |
| 66 | + const app = Realm.App.getApp("<Your App ID>"); |
0 commit comments