Skip to content

Commit ae02b2d

Browse files
committed
switched to procedure formatting
1 parent d91a3fa commit ae02b2d

File tree

1 file changed

+65
-54
lines changed

1 file changed

+65
-54
lines changed

source/frameworks/react/providers-hooks.txt

Lines changed: 65 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,24 @@ 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.
115123

116-
- ``UserProvider``: Used to access the logged-in :js-sdk:`user object <classes/Realm.User.html>`.
124+
- ``UserProvider``: Used to access the logged-in :ref:`user object <user-accounts>`.
117125

118-
- ``RealmProvider``: Used to work with the configured :js-sdk:`database <classes/Realm-1.html>`.
126+
- ``RealmProvider``: Used to work with the configured database.
119127

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

131+
.. note:: Exposing more than one database using createRealmContext()
132+
133+
The example details how to configure and expose a single database using a ``RealmProvider``
134+
imported directly from ``@realm/react``.
135+
For information about using ``createRealmContext()`` to configure a database or exposing more
136+
than one database, see :ref:`Create Context with createRealmContext()
137+
<create_context_with_createrealmcontext>` below.
138+
123139
**To configure your providers:**
124140

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

147163
c. Add other configuration object properties as props to ``RealmProvider`` as needed.
148164

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.
165+
5. Nest you app components in the providers.
166+
Once your providers have been configured, nest your app components within the
167+
provider whose context it needs to access. Generally, you can nest your components within the
168+
``RealmProvider`` to ensure they have access to all three providers' contexts.
152169

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

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-
170179
Working with Providers using Hooks
171180
----------------------------------
172181

@@ -366,12 +375,12 @@ you the name of the current operation.
366375

367376
*Enum values*
368377

369-
- ``state``. Can be "not-started", "pending", "success", "error".
370-
- ``operation``. For a list of all operation names, refer to the
378+
- ``state``: Can be ``"not-started"``, ``"pending"``, ``"success"``, ``"error"``.
379+
- ``operation``: For a list of all operation names, refer to the
371380
: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.
381+
- ``pending``: Can be ``true`` or ``false``.
382+
- ``success``: Can be ``true`` or ``false``.
383+
- ``error``: Error-based object or undefined.
375384

376385
Authentication Methods
377386
++++++++++++++++++++++
@@ -381,12 +390,13 @@ The authentication method specifies how you want users to login to your app. ``u
381390
.. list-table::
382391
:header-rows: 1
383392
:stub-columns: 1
393+
:widths: 15 20 65
384394

385395
* - Operation
386396
- Parameter
387397
- Example
388398

389-
* - ``logIn(credentials)``
399+
* - logIn
390400
- ``credentials``: An Atlas credential supplied by any supported Atlas authentication.
391401
- Logs in a user with any authentication mechanism supported by Atlas. If called when a
392402
user is logged in, the current user switches to the new user. Usually, it's better to use
@@ -411,7 +421,7 @@ The authentication method specifies how you want users to login to your app. ``u
411421
}
412422
//...
413423

414-
* - ``logInWithAnonymous``
424+
* - logInWithAnonymous
415425
- None
416426
- Log in with the anonymous authentication provider.
417427

@@ -422,7 +432,7 @@ The authentication method specifies how you want users to login to your app. ``u
422432
logInWithAnonymous();
423433
};
424434

425-
* - ``logInWithApiKey(key)``
435+
* - logInWithApiKey
426436
- ``key``: A string that is linked to an App Services user.
427437
- Log in with an API key.
428438

@@ -434,7 +444,7 @@ The authentication method specifies how you want users to login to your app. ``u
434444
logInWithApiKey(key);
435445
};
436446

437-
* - ``logInWithEmailPassword(credentials)``
447+
* - logInWithEmailPassword
438448
- ``credentials``: An object with ``email`` and ``password`` fields.
439449
- Log in with Email/Password.
440450

@@ -448,7 +458,7 @@ The authentication method specifies how you want users to login to your app. ``u
448458
logInWithEmailPassword({email, password});
449459
};
450460

451-
* - ``logInWithJWT(credentials)``
461+
* - logInWithJWT
452462
- ``credentials``: A string representation of a user's JWT.
453463
- Log in with a JSON Web Token (JWT).
454464

@@ -461,7 +471,7 @@ The authentication method specifies how you want users to login to your app. ``u
461471
logInWithJWT(token);
462472
};
463473

464-
* - ``logInWithGoogle(credentials)``
474+
* - logInWithGoogle
465475
- ``credentials``: An object with an ``idToken`` or ``authCode`` field that
466476
should contain the string token you get from Google Identity Services.
467477
- Log in with Google.
@@ -475,7 +485,7 @@ The authentication method specifies how you want users to login to your app. ``u
475485
logInWithGoogle({idToken: token});
476486
};
477487

478-
* - ``logInWithApple(idToken)``
488+
* - logInWithApple
479489
- ``idToken``: A string you get from the Apple SDK.
480490
- Log in with Apple.
481491

@@ -488,7 +498,7 @@ The authentication method specifies how you want users to login to your app. ``u
488498
logInWithApple(token);
489499
};
490500

491-
* - ``logInWithFacebook(accessToken)``
501+
* - logInWithFacebook
492502
- ``accessToken``: A string you get from the Facebook SDK.
493503
- Log in with Facebook.
494504

@@ -501,7 +511,7 @@ The authentication method specifies how you want users to login to your app. ``u
501511
logInWithFacebook(token);
502512
};
503513

504-
* - ``logInWithFunction(payload)``
514+
* - logInWithFunction
505515
- ``payload``: An object that contains user information you want to pass to
506516
the App Services function that processes log in requests.
507517
- Log in with a custom function.
@@ -515,7 +525,7 @@ The authentication method specifies how you want users to login to your app. ``u
515525
logInWithFunction(customPayload);
516526
};
517527

518-
* - ``logOut()``
528+
* - logOut
519529
- None
520530
- Logs out the current user.
521531

@@ -547,12 +557,12 @@ operation.
547557

548558
*Enum values*
549559

550-
- ``state``. Can be "not-started", "pending", "success", "error".
551-
- ``operation``. For a list of all operation names, refer to the
560+
- ``state``: Can be ``"not-started"``, ``"pending"``, ``"success"``, ``"error"``.
561+
- ``operation``: For a list of all operation names, refer to the
552562
: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.
563+
- ``pending``: Can be ``true`` or ``false``.
564+
- ``success``: Can be ``true`` or ``false``.
565+
- ``error``: Error-based object or undefined.
556566

557567
Authentication Operations
558568
+++++++++++++++++++++++++
@@ -562,12 +572,13 @@ Authentication Operations
562572
.. list-table::
563573
:header-rows: 1
564574
:stub-columns: 1
575+
:widths: 15 20 65
565576

566577
* - Operation
567578
- Parameter
568579
- Example
569580

570-
* - ``logIn(credentials)``
581+
* - logIn
571582
- ``credentials``: An object that contains ``email`` and ``password`` properties.
572583
- Logs a user in using an email and password. You could also call
573584
``logIn(Realm.Credentials.emailPassword(email, password))``. Returns a
@@ -597,7 +608,7 @@ Authentication Operations
597608
}
598609
//...
599610

600-
* - ``logOut()``
611+
* - logOut
601612
- None
602613
- Logs out the current user.
603614

@@ -608,7 +619,7 @@ Authentication Operations
608619
logOut();
609620
}
610621

611-
* - ``register(args)``
622+
* - register
612623
- ``args``: An object that contains ``email`` and ``password`` properties.
613624
- Registers a new user. Requires a user email and password.
614625

@@ -623,7 +634,7 @@ Authentication Operations
623634
register({email, password});
624635
};
625636

626-
* - ``confirm(args)``
637+
* - confirm
627638
- ``args``: An object that contains ``token`` and ``tokenId`` properties.
628639
- Confirms a user account. Requires a ``token`` and ``tokenId``.
629640

@@ -635,7 +646,7 @@ Authentication Operations
635646
confirm({token, tokenId});
636647
};
637648

638-
* - ``resendConfirmationEmail(args)``
649+
* - resendConfirmationEmail
639650
- ``args``: An object that contains an ``email`` property.
640651
- Resends a confirmation email.
641652

@@ -648,7 +659,7 @@ Authentication Operations
648659
resendConfirmationEmail({email});
649660
};
650661

651-
* - ``retryCustomConfirmation(args)``
662+
* - retryCustomConfirmation
652663
- ``args``: An object that contains an ``email`` property.
653664
- Retries confirmation with a custom function.
654665

@@ -661,7 +672,7 @@ Authentication Operations
661672
retryCustomConfirmation({email});
662673
};
663674

664-
* - ``sendResetPasswordEmail(args)``
675+
* - sendResetPasswordEmail
665676
- ``args``: An object that contains an ``email`` property.
666677
- Sends a password reset email.
667678

@@ -674,7 +685,7 @@ Authentication Operations
674685
sendResetPasswordEmail({email});
675686
};
676687

677-
* - ``resetPassword(args)``
688+
* - resetPassword
678689
- ``args``: An object that contains ``token``, ``tokenId``, and ``password``
679690
properties.
680691
- Resets a user's password.
@@ -688,7 +699,7 @@ Authentication Operations
688699
resetPassword({token, tokenId, password});
689700
};
690701

691-
* - ``callResetPasswordFunction(args, restArgs)``
702+
* - callResetPasswordFunction
692703
- ``args``: An object that contains ``email`` and ``password`` properties.
693704

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

718729
createRealmContext(realmConfig?): RealmContext
719730

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-
730731
Most of the time, you will only use ``createRealmContext()`` if you need to
731732
configure more than one database. Otherwise, you should import ``RealmProvider``
732733
and its associated Hooks directly from ``@realm/react``.
@@ -746,4 +747,14 @@ provider and use its associated Hooks the same way you would with the ``RealmPro
746747
imported from the ``@realm/react`` library. You should namespace providers
747748
to avoid confusion about which provider and Hooks you're working with.
748749

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

0 commit comments

Comments
 (0)