Skip to content

Commit

Permalink
Update README to add hook documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
dhovart committed Dec 23, 2020
1 parent cf5479a commit 0cef771
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,30 @@ class MyApp extends Component {
export default MyApp;
```

If you want to use these functions in lifecycle hooks, please pass them as props to the component in question.
If you want to use these functions in lifecycle hooks, please pass them as props to the component in question, or if you're using React 16.8+ use the `useAriaLive` hook:

```
const MyFunctionalComponent = () => {
const { announcePolite, announceAssertive } = useAriaLive();
return (
<Fragment>
<button
type="button"
onClick={() => {
announceAssertive('ASSERTIVE MESSAGE');
}}>
Press me for an assertive message
</button>
<button
type="button"
onClick={() => {
announcePolite('Polite message');
}}>
Press me for a Polite message
</button>
</Fragment>
);
};
```

Please note that your functional component should be rendered inside a `LiveAnnouncer`.

0 comments on commit 0cef771

Please sign in to comment.