Skip to content

Commit 336dc0c

Browse files
committed
Update README to add hook documentation
1 parent 529550f commit 336dc0c

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,30 @@ class MyApp extends Component {
121121
export default MyApp;
122122
```
123123

124-
If you want to use these functions in lifecycle hooks, please pass them as props to the component in question.
124+
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:
125+
126+
```
127+
const MyFunctionalComponent = () => {
128+
const { announcePolite, announceAssertive } = useAriaLive();
129+
return (
130+
<Fragment>
131+
<button
132+
type="button"
133+
onClick={() => {
134+
announceAssertive('ASSERTIVE MESSAGE');
135+
}}>
136+
Press me for an assertive message
137+
</button>
138+
<button
139+
type="button"
140+
onClick={() => {
141+
announcePolite('Polite message');
142+
}}>
143+
Press me for a Polite message
144+
</button>
145+
</Fragment>
146+
);
147+
};
148+
```
149+
150+
Please note that your functional component should be rendered inside a `LiveAnnouncer`.

0 commit comments

Comments
 (0)