Skip to content

Commit 1c15fe6

Browse files
committed
improve unreleased, adjust keypress function order
1 parent 680663e commit 1c15fe6

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
@@ -16,6 +16,8 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f
1616
- Add `status` prop to `IndexTable.Row` to allow table rows to specify background colors([#4146](https://github.com/Shopify/polaris-react/pull/4146))
1717
- Added `useIsomorphicLayout` ([#4173](https://github.com/Shopify/polaris-react/pull/4173))
1818
- Prevent `KeypressListener` attaching/detaching on every render ([#4173](https://github.com/Shopify/polaris-react/pull/4173))
19+
- Added `useIsomorphicLayoutEffect` hook ([#4173](https://github.com/Shopify/polaris-react/pull/4173))
20+
- Prevented `KeypressListener` attaching/detaching on every render ([#4173](https://github.com/Shopify/polaris-react/pull/4173))
1921

2022
### Bug fixes
2123

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)