Skip to content

Commit

Permalink
fix: avoid unnecessary rerenders using stable default prop references…
Browse files Browse the repository at this point in the history
… (partial)
  • Loading branch information
amcgee committed Sep 25, 2024
1 parent 371fdb0 commit 1210dff
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 18 deletions.
1 change: 0 additions & 1 deletion components/button/src/split-button/split-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class SplitButton extends Component {

const arrow = open ? <IconChevronUp16 /> : <IconChevronDown16 />

console.log(dataTest)
return (
<div ref={this.anchorRef} data-test={dataTest}>
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class FileInputFieldWithList extends Component {
render() {
const {
accept,
buttonLabel = () => i18n.t('Upload a file'),
buttonLabel = FileInputFieldWithList.defaultProps.buttonLabel,
className,
dataTest = 'dhis2-uiwidgets-fileinputfieldwithlist',
disabled,
Expand All @@ -85,8 +85,8 @@ class FileInputFieldWithList extends Component {
onBlur,
onFocus,
onKeyDown,
placeholder = () => i18n.t('No file uploaded yet'),
removeText = () => i18n.t('Remove'),
placeholder = FileInputFieldWithList.defaultProps.placeholder,
removeText = FileInputFieldWithList.defaultProps.removeText,
required,
small,
tabIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ const translate = (prop, interpolationObject) => {
return prop
}

const defaultButtonLabel = () => i18n.t('Upload a file')
const defaultPlaceholder = () => i18n.t('No file uploaded yet')
const FileInputField = ({
accept = '*',
buttonLabel = () => i18n.t('Upload a file'),
buttonLabel = defaultButtonLabel,
children,
className,
dataTest = 'dhis2-uiwidgets-fileinputfield',
Expand All @@ -34,7 +36,7 @@ const FileInputField = ({
onChange,
onFocus,
onKeyDown,
placeholder = () => i18n.t('No file uploaded yet'),
placeholder = defaultPlaceholder,
required,
small,
tabIndex,
Expand Down
22 changes: 12 additions & 10 deletions components/sharing-dialog/src/sharing-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,21 @@ const mutation = {
data: ({ data }) => data,
}

const emptyFunction = () => {}
const defaultInitialSharingSettings = {
name: '',
allowPublic: true,
public: ACCESS_NONE,
groups: {},
users: {},
}
export const SharingDialog = ({
id,
type,
onClose = () => {},
onError = () => {},
onSave = () => {},
initialSharingSettings = {
name: '',
allowPublic: true,
public: ACCESS_NONE,
groups: {},
users: {},
},
onClose = emptyFunction,
onError = emptyFunction,
onSave = emptyFunction,
initialSharingSettings = defaultInitialSharingSettings,
dataTest = 'dhis2-uicore-sharingdialog',
}) => {
const { show: showError } = useAlert((error) => error, { critical: true })
Expand Down
3 changes: 2 additions & 1 deletion components/table/src/stacked-table/stacked-table-cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import PropTypes from 'prop-types'
import React from 'react'
import { ContentWithTitle } from './content-with-title.js'

const defaultHeaderLabels = []
export const StackedTableCell = ({
children,
className,
colSpan,
column,
dataTest = 'dhis2-uicore-stackedtablecell',
headerLabels = [],
headerLabels = defaultHeaderLabels,
hideTitle,
rowSpan,
title,
Expand Down
3 changes: 2 additions & 1 deletion components/transfer/src/transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
import { TransferOption } from './transfer-option.js'

const identity = (value) => value
const defaultSelected = []

export const Transfer = ({
options,
Expand Down Expand Up @@ -70,7 +71,7 @@ export const Transfer = ({
rightHeader,
searchTerm,
searchTermPicked,
selected = [],
selected = defaultSelected,
selectedEmptyComponent,
selectedWidth = '320px',
sourceEmptyPlaceholder,
Expand Down

0 comments on commit 1210dff

Please sign in to comment.