mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 09:36:27 +00:00
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.
This commit is contained in:
@@ -10,7 +10,7 @@ import AboutDialog from './AboutDialog';
|
||||
it('should close when the button is clicked', () => {
|
||||
const close = jest.fn();
|
||||
|
||||
const [dialog] = testRender(<AboutDialog isOpen={true} onClose={() => close()} />);
|
||||
const [dialog] = testRender(<AboutDialog isOpen={true} onClose={close} />);
|
||||
|
||||
userEvent.click(dialog.getByLabelText('Close'));
|
||||
|
||||
|
||||
@@ -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<AboutDialogProps> = (props) => {
|
||||
<Dialog
|
||||
title={`Pybricks v${firmwareVersion} (${appName} v${appVersion})`}
|
||||
isOpen={props.isOpen}
|
||||
onClose={() => props.onClose()}
|
||||
onClose={props.onClose}
|
||||
>
|
||||
<div className={Classes.DIALOG_BODY}>
|
||||
<div className="pb-about-icon">
|
||||
|
||||
@@ -55,7 +55,7 @@ const ActionButton: React.VoidFunctionComponent<ActionButtonProps> = (props) =>
|
||||
title={i18n.translate(props.toolTipId, props.toolTipReplacements)}
|
||||
disabled={props.disabled}
|
||||
onMouseDown={preventFocusOnClick}
|
||||
onClick={() => props.onClick()}
|
||||
onClick={props.onClick}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -51,15 +51,15 @@ const NewFileWizard: React.VoidFunctionComponent<NewFileWizardProps> = (props) =
|
||||
isOpen={props.isOpen}
|
||||
onOpening={() => setFileName('')}
|
||||
onOpened={() => fileNameInputRef.current?.focus()}
|
||||
onClose={() => props.onClose()}
|
||||
onClose={props.onClose}
|
||||
>
|
||||
<div className={Classes.DIALOG_BODY}>
|
||||
<FileNameFormGroup
|
||||
fileName={fileName}
|
||||
fileExtension={pythonFileExtension}
|
||||
inputRef={fileNameInputRef}
|
||||
onChange={(n) => setFileName(n)}
|
||||
onValidation={(r) => setFileNameValidation(r)}
|
||||
onChange={setFileName}
|
||||
onValidation={setFileNameValidation}
|
||||
/>
|
||||
<FormGroup label={i18n.translate(NewFileWizardStringId.SmartHubLabel)}>
|
||||
<RadioGroup
|
||||
|
||||
@@ -52,8 +52,8 @@ const RenameFileDialog: React.VoidFunctionComponent<RenameFileDialogProps> = (
|
||||
fileName={newName}
|
||||
fileExtension={extension}
|
||||
inputRef={inputRef}
|
||||
onChange={(n) => setNewName(n)}
|
||||
onValidation={(r) => setResult(r)}
|
||||
onChange={setNewName}
|
||||
onValidation={setResult}
|
||||
/>
|
||||
</div>
|
||||
<div className={Classes.DIALOG_FOOTER}>
|
||||
|
||||
@@ -92,7 +92,7 @@ const SettingsDrawer: React.FunctionComponent<SettingsProps> = (props) => {
|
||||
icon="cog"
|
||||
size={Drawer.SIZE_SMALL}
|
||||
title={i18n.translate(SettingsStringId.Title)}
|
||||
onClose={() => props.onClose()}
|
||||
onClose={props.onClose}
|
||||
>
|
||||
<div className={Classes.DRAWER_BODY}>
|
||||
<div className={Classes.DIALOG_BODY}>
|
||||
|
||||
@@ -106,7 +106,7 @@ const ActionButton: React.FC<ActionButtonProps> = (props) => {
|
||||
{...tooltipTargetProps}
|
||||
intent={Intent.PRIMARY}
|
||||
onMouseDown={preventFocusOnClick}
|
||||
onClick={() => props.onAction()}
|
||||
onClick={props.onAction}
|
||||
disabled={props.enabled === false}
|
||||
style={
|
||||
props.enabled === false ? { pointerEvents: 'none' } : undefined
|
||||
|
||||
Reference in New Issue
Block a user