Skip to content

Commit 941e596

Browse files
committed
switched to procedure formatting
1 parent d91a3fa commit 941e596

File tree

1 file changed

+71
-54
lines changed

1 file changed

+71
-54
lines changed

source/frameworks/react/providers-hooks.txt

Lines changed: 71 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ develop a React app using JavaScript-based Atlas Device SDKs. The components lev
2727
provider design pattern to manage your Atlas connection, user creation and authentication, and
2828
data management.
2929

30+
- :realm-react-sdk:`AppProvider (@realm/react) <functions/AppProvider.html>`
31+
32+
- :realm-react-sdk:`UserProvider (@realm/react) <functions/UserProvider.html>`
33+
34+
- :realm-react-sdk:`RealmProvider (@realm/react) <functions/RealmProvider.html>`
35+
3036
The providers are available in all SDKs that support a React environment. This includes React
3137
Native, Web, and Electron.
3238

@@ -99,6 +105,8 @@ Provider has different props you can use for configuration.
99105
.. tab:: UserProvider Props
100106
:tabid: user-provider-props
101107

108+
The only prop passed into ``UserProvider`` is an optional fallback component:
109+
102110
- ``fallback?: React.ComponentType<unknown> | React.ReactElement | null | undefined``
103111

104112
The fallback component to render if there is no authorized user. This can be
@@ -110,16 +118,30 @@ Configure your Providers
110118
Your app's needs determine what providers you use, as all three providers are not always
111119
necessary:
112120

113-
- ``AppProvider``: Used to connect to your :js-sdk:`Atlas App Services App Client
114-
<classes/Realm.App-1.html>`, including for user authentication.
121+
- ``AppProvider``: Used to connect to your :ref:`Atlas App Services App Client
122+
<create-app>`, including for user authentication.
123+
124+
- For more information, refer to the :js-sdk:`Realm App API documentation <classes/Realm.App-1.html>`.
125+
126+
- ``UserProvider``: Used to access the logged-in :ref:`user object <user-accounts>`.
115127

116-
- ``UserProvider``: Used to access the logged-in :js-sdk:`user object <classes/Realm.User.html>`.
128+
- For more information, refer to the :js-sdk:`Realm User API documentation <classes/Realm.User.html>`.
117129

118-
- ``RealmProvider``: Used to work with the configured :js-sdk:`database <classes/Realm-1.html>`.
130+
- ``RealmProvider``: Used to work with the configured database.
131+
132+
- For more information, refer to the :js-sdk:`Realm API documentation <classes/Realm-1.html>`.
119133

120134
The example below walks through configuring all three providers. If your app does not need a
121135
certain provider, you can skip the steps and omit the code for that provider.
122136

137+
.. note:: Exposing more than one database using createRealmContext()
138+
139+
The example details how to configure and expose a single database using a ``RealmProvider``
140+
imported directly from ``@realm/react``.
141+
For information about using ``createRealmContext()`` to configure a database or exposing more
142+
than one database, see :ref:`Create Context with createRealmContext()
143+
<create_context_with_createrealmcontext>` below.
144+
123145
**To configure your providers:**
124146

125147
1. Import ``RealmProvider``, ``AppProvider``, and ``UserProvider`` from ``@realm/react``.
@@ -146,9 +168,10 @@ certain provider, you can skip the steps and omit the code for that provider.
146168

147169
c. Add other configuration object properties as props to ``RealmProvider`` as needed.
148170

149-
Once your providers have been configured, nest your app components within the
150-
provider whose context it needs to access. Generally, you can nest your components within the
151-
``RealmProvider`` to ensure they have access to all three providers' contexts.
171+
5. Nest you app components in the providers.
172+
Once your providers have been configured, nest your app components within the
173+
provider whose context it needs to access. Generally, you can nest your components within the
174+
``RealmProvider`` to ensure they have access to all three providers' contexts.
152175

153176
The rendering of each component is dependent on the successful
154177
execution of its parent components' functionality. For example, if ``AppProvider`` cannot
@@ -159,14 +182,6 @@ You *must* nest the providers as shown below to ensure each has access to its re
159182
.. literalinclude:: /examples/generated/react-native/ts/configure-realm-sync.test.snippet.configure-realm-sync-full.tsx
160183
:language: javascript
161184

162-
.. note::
163-
164-
The example details how to configure and expose a single database using a ``RealmProvider``
165-
imported directly from ``@realm/react``.
166-
For information about using ``createRealmContext()`` to configure a database or exposing more
167-
than one database, see :ref:`Create Context with createRealmContext()
168-
<create_context_with_createrealmcontext>` below.
169-
170185
Working with Providers using Hooks
171186
----------------------------------
172187

@@ -366,12 +381,12 @@ you the name of the current operation.
366381

367382
*Enum values*
368383

369-
- ``state``. Can be "not-started", "pending", "success", "error".
370-
- ``operation``. For a list of all operation names, refer to the
384+
- ``state``: Can be ``"not-started"``, ``"pending"``, ``"success"``, ``"error"``.
385+
- ``operation``: For a list of all operation names, refer to the
371386
:realm-react-sdk:`API documentation <enums/AuthOperationName.html>`.
372-
- ``pending``. Can be ``true`` or ``false``.
373-
- ``success``. Can be ``true`` or ``false``.
374-
- ``error``. Error-based object or undefined.
387+
- ``pending``: Can be ``true`` or ``false``.
388+
- ``success``: Can be ``true`` or ``false``.
389+
- ``error``: Error-based object or undefined.
375390

376391
Authentication Methods
377392
++++++++++++++++++++++
@@ -381,12 +396,13 @@ The authentication method specifies how you want users to login to your app. ``u
381396
.. list-table::
382397
:header-rows: 1
383398
:stub-columns: 1
399+
:widths: 15 20 65
384400

385401
* - Operation
386402
- Parameter
387403
- Example
388404

389-
* - ``logIn(credentials)``
405+
* - logIn
390406
- ``credentials``: An Atlas credential supplied by any supported Atlas authentication.
391407
- Logs in a user with any authentication mechanism supported by Atlas. If called when a
392408
user is logged in, the current user switches to the new user. Usually, it's better to use
@@ -411,7 +427,7 @@ The authentication method specifies how you want users to login to your app. ``u
411427
}
412428
//...
413429

414-
* - ``logInWithAnonymous``
430+
* - logInWithAnonymous
415431
- None
416432
- Log in with the anonymous authentication provider.
417433

@@ -422,7 +438,7 @@ The authentication method specifies how you want users to login to your app. ``u
422438
logInWithAnonymous();
423439
};
424440

425-
* - ``logInWithApiKey(key)``
441+
* - logInWithApiKey
426442
- ``key``: A string that is linked to an App Services user.
427443
- Log in with an API key.
428444

@@ -434,7 +450,7 @@ The authentication method specifies how you want users to login to your app. ``u
434450
logInWithApiKey(key);
435451
};
436452

437-
* - ``logInWithEmailPassword(credentials)``
453+
* - logInWithEmailPassword
438454
- ``credentials``: An object with ``email`` and ``password`` fields.
439455
- Log in with Email/Password.
440456

@@ -448,7 +464,7 @@ The authentication method specifies how you want users to login to your app. ``u
448464
logInWithEmailPassword({email, password});
449465
};
450466

451-
* - ``logInWithJWT(credentials)``
467+
* - logInWithJWT
452468
- ``credentials``: A string representation of a user's JWT.
453469
- Log in with a JSON Web Token (JWT).
454470

@@ -461,7 +477,7 @@ The authentication method specifies how you want users to login to your app. ``u
461477
logInWithJWT(token);
462478
};
463479

464-
* - ``logInWithGoogle(credentials)``
480+
* - logInWithGoogle
465481
- ``credentials``: An object with an ``idToken`` or ``authCode`` field that
466482
should contain the string token you get from Google Identity Services.
467483
- Log in with Google.
@@ -475,7 +491,7 @@ The authentication method specifies how you want users to login to your app. ``u
475491
logInWithGoogle({idToken: token});
476492
};
477493

478-
* - ``logInWithApple(idToken)``
494+
* - logInWithApple
479495
- ``idToken``: A string you get from the Apple SDK.
480496
- Log in with Apple.
481497

@@ -488,7 +504,7 @@ The authentication method specifies how you want users to login to your app. ``u
488504
logInWithApple(token);
489505
};
490506

491-
* - ``logInWithFacebook(accessToken)``
507+
* - logInWithFacebook
492508
- ``accessToken``: A string you get from the Facebook SDK.
493509
- Log in with Facebook.
494510

@@ -501,7 +517,7 @@ The authentication method specifies how you want users to login to your app. ``u
501517
logInWithFacebook(token);
502518
};
503519

504-
* - ``logInWithFunction(payload)``
520+
* - logInWithFunction
505521
- ``payload``: An object that contains user information you want to pass to
506522
the App Services function that processes log in requests.
507523
- Log in with a custom function.
@@ -515,7 +531,7 @@ The authentication method specifies how you want users to login to your app. ``u
515531
logInWithFunction(customPayload);
516532
};
517533

518-
* - ``logOut()``
534+
* - logOut
519535
- None
520536
- Logs out the current user.
521537

@@ -547,12 +563,12 @@ operation.
547563

548564
*Enum values*
549565

550-
- ``state``. Can be "not-started", "pending", "success", "error".
551-
- ``operation``. For a list of all operation names, refer to the
566+
- ``state``: Can be ``"not-started"``, ``"pending"``, ``"success"``, ``"error"``.
567+
- ``operation``: For a list of all operation names, refer to the
552568
:realm-react-sdk:`API documentation <enums/AuthOperationName.html>`.
553-
- ``pending``. Can be ``true`` or ``false``.
554-
- ``success``. Can be ``true`` or ``false``.
555-
- ``error``. Error-based object or undefined.
569+
- ``pending``: Can be ``true`` or ``false``.
570+
- ``success``: Can be ``true`` or ``false``.
571+
- ``error``: Error-based object or undefined.
556572

557573
Authentication Operations
558574
+++++++++++++++++++++++++
@@ -562,12 +578,13 @@ Authentication Operations
562578
.. list-table::
563579
:header-rows: 1
564580
:stub-columns: 1
581+
:widths: 15 20 65
565582

566583
* - Operation
567584
- Parameter
568585
- Example
569586

570-
* - ``logIn(credentials)``
587+
* - logIn
571588
- ``credentials``: An object that contains ``email`` and ``password`` properties.
572589
- Logs a user in using an email and password. You could also call
573590
``logIn(Realm.Credentials.emailPassword(email, password))``. Returns a
@@ -597,7 +614,7 @@ Authentication Operations
597614
}
598615
//...
599616

600-
* - ``logOut()``
617+
* - logOut
601618
- None
602619
- Logs out the current user.
603620

@@ -608,7 +625,7 @@ Authentication Operations
608625
logOut();
609626
}
610627

611-
* - ``register(args)``
628+
* - register
612629
- ``args``: An object that contains ``email`` and ``password`` properties.
613630
- Registers a new user. Requires a user email and password.
614631

@@ -623,7 +640,7 @@ Authentication Operations
623640
register({email, password});
624641
};
625642

626-
* - ``confirm(args)``
643+
* - confirm
627644
- ``args``: An object that contains ``token`` and ``tokenId`` properties.
628645
- Confirms a user account. Requires a ``token`` and ``tokenId``.
629646

@@ -635,7 +652,7 @@ Authentication Operations
635652
confirm({token, tokenId});
636653
};
637654

638-
* - ``resendConfirmationEmail(args)``
655+
* - resendConfirmationEmail
639656
- ``args``: An object that contains an ``email`` property.
640657
- Resends a confirmation email.
641658

@@ -648,7 +665,7 @@ Authentication Operations
648665
resendConfirmationEmail({email});
649666
};
650667

651-
* - ``retryCustomConfirmation(args)``
668+
* - retryCustomConfirmation
652669
- ``args``: An object that contains an ``email`` property.
653670
- Retries confirmation with a custom function.
654671

@@ -661,7 +678,7 @@ Authentication Operations
661678
retryCustomConfirmation({email});
662679
};
663680

664-
* - ``sendResetPasswordEmail(args)``
681+
* - sendResetPasswordEmail
665682
- ``args``: An object that contains an ``email`` property.
666683
- Sends a password reset email.
667684

@@ -674,7 +691,7 @@ Authentication Operations
674691
sendResetPasswordEmail({email});
675692
};
676693

677-
* - ``resetPassword(args)``
694+
* - resetPassword
678695
- ``args``: An object that contains ``token``, ``tokenId``, and ``password``
679696
properties.
680697
- Resets a user's password.
@@ -688,7 +705,7 @@ Authentication Operations
688705
resetPassword({token, tokenId, password});
689706
};
690707

691-
* - ``callResetPasswordFunction(args, restArgs)``
708+
* - callResetPasswordFunction
692709
- ``args``: An object that contains ``email`` and ``password`` properties.
693710

694711
``restArgs``: Additional arguments that you need to pass to your custom
@@ -717,16 +734,6 @@ Create Context with createRealmContext()
717734

718735
createRealmContext(realmConfig?): RealmContext
719736

720-
*Parameters*
721-
722-
- ``realmConfig?: Realm.Configuration`` All properties of :realm-react-sdk:`BaseConfiguration
723-
<types/Realm.BaseConfiguration.html>` can be used.
724-
725-
*Returns*
726-
727-
- ``RealmContext`` An object containing a ``RealmProvider`` component, and the ``useRealm``,
728-
``useQuery`` and ``useObject`` Hooks.
729-
730737
Most of the time, you will only use ``createRealmContext()`` if you need to
731738
configure more than one database. Otherwise, you should import ``RealmProvider``
732739
and its associated Hooks directly from ``@realm/react``.
@@ -746,4 +753,14 @@ provider and use its associated Hooks the same way you would with the ``RealmPro
746753
imported from the ``@realm/react`` library. You should namespace providers
747754
to avoid confusion about which provider and Hooks you're working with.
748755

756+
*Parameters*
757+
758+
- ``realmConfig?: Realm.Configuration`` All properties of :realm-react-sdk:`BaseConfiguration
759+
<types/Realm.BaseConfiguration.html>` can be used.
760+
761+
*Returns*
762+
763+
- ``RealmContext`` An object containing a ``RealmProvider`` component, and the ``useRealm``,
764+
``useQuery`` and ``useObject`` Hooks.
765+
749766
For a detailed guide, refer to :ref:`Expose More Than One Database <sdks-expose-more-than-one-database>`.

0 commit comments

Comments
 (0)