Skip to content

Commit f7b1523

Browse files
authored
docs: add useEffect usage example
1 parent 729df9c commit f7b1523

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,23 @@ return (
7777
```
7878

7979
The above example will report the `clientWidth` rather than the default `offsetWidth` and `offsetHeight`.
80+
81+
## React to size variations
82+
83+
For completeness, below you can find an example to show how to make your code react to size variations using React Hooks:
84+
85+
``jsx
86+
const App = () => {
87+
const [resizeListener, sizes] = useResizeAware(customReporter);
88+
89+
React.useEffect(() => {
90+
console.log('Do something with the new size values');
91+
}, [sizes.width, sizes.height]);
92+
93+
return (
94+
<div style={{ position: 'relative' }}>
95+
{resizeListener}
96+
Your content here.
97+
</div>
98+
);
99+
}

0 commit comments

Comments
 (0)