From de7e046d313c2da32f96060d1c12f3c8662ad86b Mon Sep 17 00:00:00 2001 From: David Lechner Date: Sat, 12 Mar 2022 15:08:06 -0600 Subject: [PATCH] avoid lambda props This fixes the simple cases of callback props using lambda functions. This will prevent rerendering in some cases since a new callback function is not created on each call. --- src/about/AboutDialog.test.tsx | 2 +- src/about/AboutDialog.tsx | 4 ++-- src/explorer/Explorer.tsx | 2 +- src/explorer/NewFileWizard.tsx | 6 +++--- src/explorer/RenameFileDialog.tsx | 4 ++-- src/settings/SettingsDrawer.tsx | 2 +- src/toolbar/ActionButton.tsx | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/about/AboutDialog.test.tsx b/src/about/AboutDialog.test.tsx index ce25204c..08eefcdc 100644 --- a/src/about/AboutDialog.test.tsx +++ b/src/about/AboutDialog.test.tsx @@ -10,7 +10,7 @@ import AboutDialog from './AboutDialog'; it('should close when the button is clicked', () => { const close = jest.fn(); - const [dialog] = testRender( close()} />); + const [dialog] = testRender(); userEvent.click(dialog.getByLabelText('Close')); diff --git a/src/about/AboutDialog.tsx b/src/about/AboutDialog.tsx index 0d9eeceb..2081e9e5 100644 --- a/src/about/AboutDialog.tsx +++ b/src/about/AboutDialog.tsx @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2021 The Pybricks Authors +// Copyright (c) 2021-2022 The Pybricks Authors // The about dialog @@ -33,7 +33,7 @@ const AboutDialog: React.FunctionComponent = (props) => { props.onClose()} + onClose={props.onClose} >
diff --git a/src/explorer/Explorer.tsx b/src/explorer/Explorer.tsx index 39e8b90b..5fdafd4c 100644 --- a/src/explorer/Explorer.tsx +++ b/src/explorer/Explorer.tsx @@ -55,7 +55,7 @@ const ActionButton: React.VoidFunctionComponent = (props) => title={i18n.translate(props.toolTipId, props.toolTipReplacements)} disabled={props.disabled} onMouseDown={preventFocusOnClick} - onClick={() => props.onClick()} + onClick={props.onClick} /> ); }; diff --git a/src/explorer/NewFileWizard.tsx b/src/explorer/NewFileWizard.tsx index ad2db0fb..11377a92 100644 --- a/src/explorer/NewFileWizard.tsx +++ b/src/explorer/NewFileWizard.tsx @@ -51,15 +51,15 @@ const NewFileWizard: React.VoidFunctionComponent = (props) = isOpen={props.isOpen} onOpening={() => setFileName('')} onOpened={() => fileNameInputRef.current?.focus()} - onClose={() => props.onClose()} + onClose={props.onClose} >
setFileName(n)} - onValidation={(r) => setFileNameValidation(r)} + onChange={setFileName} + onValidation={setFileNameValidation} /> = ( fileName={newName} fileExtension={extension} inputRef={inputRef} - onChange={(n) => setNewName(n)} - onValidation={(r) => setResult(r)} + onChange={setNewName} + onValidation={setResult} />
diff --git a/src/settings/SettingsDrawer.tsx b/src/settings/SettingsDrawer.tsx index f115bc7b..2b1525dd 100644 --- a/src/settings/SettingsDrawer.tsx +++ b/src/settings/SettingsDrawer.tsx @@ -92,7 +92,7 @@ const SettingsDrawer: React.FunctionComponent = (props) => { icon="cog" size={Drawer.SIZE_SMALL} title={i18n.translate(SettingsStringId.Title)} - onClose={() => props.onClose()} + onClose={props.onClose} >
diff --git a/src/toolbar/ActionButton.tsx b/src/toolbar/ActionButton.tsx index 3550bb5c..ce92b61d 100644 --- a/src/toolbar/ActionButton.tsx +++ b/src/toolbar/ActionButton.tsx @@ -106,7 +106,7 @@ const ActionButton: React.FC = (props) => { {...tooltipTargetProps} intent={Intent.PRIMARY} onMouseDown={preventFocusOnClick} - onClick={() => props.onAction()} + onClick={props.onAction} disabled={props.enabled === false} style={ props.enabled === false ? { pointerEvents: 'none' } : undefined