Skip to content

Commit ef8ec0a

Browse files
committed
improve unreleased, adjust keypress function order
1 parent 319d53f commit ef8ec0a

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

UNRELEASED.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f
1717
- Disabled `pointer-events` on the prefix and suffix elements of the `TextField` component ([#4207](https://github.com/Shopify/polaris-react/pull/4207))
1818
- Added `useIsomorphicLayout` ([#4173](https://github.com/Shopify/polaris-react/pull/4173))
1919
- Prevent `KeypressListener` attaching/detaching on every render ([#4173](https://github.com/Shopify/polaris-react/pull/4173))
20+
- Added `useIsomorphicLayoutEffect` hook ([#4173](https://github.com/Shopify/polaris-react/pull/4173))
21+
- Prevented `KeypressListener` attaching/detaching on every render ([#4173](https://github.com/Shopify/polaris-react/pull/4173))
2022

2123
### Bug fixes
2224

src/components/KeypressListener/KeypressListener.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ export function KeypressListener({
1818
}: KeypressListenerProps) {
1919
const tracked = useRef({handler, keyCode});
2020

21+
useIsomorphicLayoutEffect(() => {
22+
tracked.current = {handler, keyCode};
23+
}, [handler, keyCode]);
24+
2125
const handleKeyEvent = useCallback((event: KeyboardEvent) => {
2226
const {handler, keyCode} = tracked.current;
2327
if (event.keyCode === keyCode) {
2428
handler(event);
2529
}
2630
}, []);
2731

28-
useIsomorphicLayoutEffect(() => {
29-
tracked.current = {handler, keyCode};
30-
}, [handler, keyCode]);
31-
3232
useEffect(() => {
3333
document.addEventListener(keyEvent, handleKeyEvent);
3434
return () => {

0 commit comments

Comments
 (0)