-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update react documentation to match latest #1168
- Loading branch information
Showing
9 changed files
with
40 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
docs/src/pages/components/authenticator/advanced/current-user.react.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
docs/src/pages/components/authenticator/advanced/example.react.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
```js{3,10-33} file=../../../../../../examples/next/pages/ui/components/authenticator/useAuthenticator/index.page.tsx#L1-L33 | ||
```js{3,10-34} file=../../../../../../examples/next/pages/ui/components/authenticator/useAuthenticator/index.page.tsx#L1-L34 | ||
``` |
10 changes: 1 addition & 9 deletions
10
docs/src/pages/components/authenticator/advanced/full-api.react.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1 @@ | ||
import { Alert } from '@aws-amplify/ui-react'; | ||
|
||
On top of `useAuthenticator*` hooks above, `@aws-amplify/ui-react` provides overarching `useAuthenticator` hook that returns all contexts corresponding to current authenticator state. See table below for the full API list. | ||
|
||
<Alert variation="warning"> | ||
We highly suggest using `useAuthenticator*` hook instead for most cases to | ||
prevent undesirable rerenders. Please see [Rendering | ||
Optimizations](#rendering-optimizations) below for more context. | ||
</Alert> | ||
Below is the full list of context that `useAuthenticator` hook returns. |
2 changes: 1 addition & 1 deletion
2
docs/src/pages/components/authenticator/advanced/full-api.vue.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
The `useAuthenticator` composable above, provides all contexts corresponding to current authenticator state. See table below for the full API list. | ||
Below is the full list of context that `useAuthenticator` composable returns. |
43 changes: 0 additions & 43 deletions
43
docs/src/pages/components/authenticator/advanced/render-optimizations.react.mdx
This file was deleted.
Oops, something went wrong.
12 changes: 4 additions & 8 deletions
12
docs/src/pages/components/authenticator/advanced/trigger-transitions.react.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,11 @@ | ||
You can use `useAuthenticatorTransitions` hook to access functions that lets you trigger transitions to the authenticator. Please see [Full API]() to see all supported transition functions. Any invalid transitions (e.g. `signUp` directly to `authenticated`) will be ignored. | ||
|
||
```tsx{1,4-5,7} | ||
import { | ||
useAuthenticatorUser, | ||
useAuthenticatorTransitions, | ||
} from '@aws-amplify/ui-react'; | ||
```tsx{1,4-6} | ||
import { useAuthenticator } from '@aws-amplify/ui-react'; | ||
const Home = () => { | ||
const user = useAuthenticatorUser(); | ||
const { signOut } = useAuthenticatorTransitions(); | ||
const { user, signOut } = useAuthenticator((context) => [context.user]); | ||
return <h2>Welcome, {user.username}!</h2>; | ||
return <button onClick={signOut}>Welcome, {user.username}!</button>; | ||
}; | ||
``` |
32 changes: 30 additions & 2 deletions
32
docs/src/pages/components/authenticator/advanced/useAuthenticator.react.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,39 @@ | ||
`@aws-amplify/ui-react` ships with `useAuthenticator` React hooks that can be used to access, modify, and update Authenticator's auth state. To use them, first wrap your application with `<Authenticator.Provider>`: | ||
### useAuthenticator Hook | ||
|
||
`@aws-amplify/ui-react` ships with `useAuthenticator` React hook that can be used to access, modify, and update Authenticator's auth state. To use them, first wrap your application with `<Authenticator.Provider>`: | ||
|
||
```tsx | ||
import { Authenticator } from '@aws-amplify/ui-react'; | ||
|
||
export default = () => ( | ||
export default () => ( | ||
<Authenticator.Provider> | ||
<App /> | ||
</AmplifyProvider> | ||
); | ||
``` | ||
|
||
Then, you can use `useAuthenticator` on your App: | ||
|
||
```tsx | ||
import { useAuthenticator } from '@aws-amplify/ui-react'; | ||
|
||
const App = () => { | ||
const { user, signOut } = useAuthenticator((context) => [context.user]); | ||
// ... | ||
}; | ||
``` | ||
|
||
### Prevent Re-renders | ||
|
||
Using `useAuthenticator` hook at your `App` level is risky, because it'll trigger a re-render down its true whenever any of its context changes value. | ||
|
||
To prevent undesired re-renders, you can pass a function to `useAuthenticator` that takes in Authenticator context and returns an array of desired context values. This hook will only trigger re-render if any of the array values change. | ||
|
||
For example, you can ensure `useAuthenticator` to only reevaluate when its `user` context changes: | ||
|
||
```tsx | ||
import { useAuthenticator } from '@aws-amplify/ui-react'; | ||
|
||
// hook below is only reevaluated when `user` changes | ||
const { user, signOut } = useAuthenticator((context) => [context.user]); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters