Skip to content

Commit 5834b1e

Browse files
feat(components): use typedMemo & fix types
1 parent cf82910 commit 5834b1e

26 files changed

+111
-111
lines changed

lib/components/accordion/accordion-button.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import type { AccordionButtonProps as ChakraAccordionButtonProps, ComponentWithAs } from '@chakra-ui/react';
22
import { AccordionButton as ChakraAccordionButton, forwardRef } from '@chakra-ui/react';
33
import { truncate } from 'lodash-es';
4-
import { memo, useMemo } from 'react';
4+
import { useMemo } from 'react';
55

6+
import { typedMemo } from '../../util';
67
import { Badge } from '../badge';
78
import { Spacer } from '../spacer';
89
import { AccordionIcon } from './wrapper';
@@ -11,11 +12,10 @@ export type AccordionButtonProps = ChakraAccordionButtonProps & {
1112
badges?: (string | number)[];
1213
};
1314

14-
export type AccordionButtonComponent = React.MemoExoticComponent<
15-
ComponentWithAs<ComponentWithAs<'button', ChakraAccordionButtonProps>, AccordionButtonProps>
16-
>;
17-
18-
export const AccordionButton: AccordionButtonComponent = memo(
15+
export const AccordionButton: ComponentWithAs<
16+
ComponentWithAs<'button', ChakraAccordionButtonProps>,
17+
AccordionButtonProps
18+
> = typedMemo(
1919
forwardRef<AccordionButtonProps, typeof ChakraAccordionButton>((props, ref) => {
2020
const { children, badges: _badges, ...rest } = props;
2121
const badges = useMemo<string[] | undefined>(

lib/components/accordion/standalone-accordion.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import type { AccordionProps as ChakraAccordionProps, ComponentWithAs } from '@chakra-ui/react';
12
import type { MouseEventHandler, PropsWithChildren } from 'react';
2-
import { memo, useCallback } from 'react';
3+
import { useCallback } from 'react';
34

5+
import { typedMemo } from '../../util';
46
import { AccordionButton } from './accordion-button';
57
import { Accordion, AccordionItem, AccordionPanel } from './wrapper';
68

@@ -11,7 +13,10 @@ export type StandaloneAccordionProps = PropsWithChildren<{
1113
onToggle: () => void;
1214
}>;
1315

14-
export const StandaloneAccordion = memo((props: StandaloneAccordionProps) => {
16+
export const StandaloneAccordion: ComponentWithAs<
17+
ComponentWithAs<'div', ChakraAccordionProps>,
18+
StandaloneAccordionProps
19+
> = typedMemo((props) => {
1520
const onClick = useCallback<MouseEventHandler<HTMLButtonElement>>(
1621
(e) => {
1722
e.preventDefault();

lib/components/alert-dialog/confirmation-alert-dialog.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import type { PropsWithChildren } from 'react';
2-
import { memo, useCallback, useRef } from 'react';
2+
import { useCallback, useRef } from 'react';
33
import { useTranslation } from 'react-i18next';
44

5+
import { typedMemo } from '../../util';
56
import { Button } from '../button';
67
import type { AlertDialogProps } from './wrapper';
78
import {
@@ -28,7 +29,7 @@ export type ConfirmationAlertDialogProps = Omit<AlertDialogProps, 'leastDestruct
2829
* This component is a wrapper around AlertDialog that provides a confirmation dialog.
2930
* Its state must be managed externally using chakra's `useDisclosure()` hook.
3031
*/
31-
export const ConfirmationAlertDialog = memo((props: ConfirmationAlertDialogProps) => {
32+
export const ConfirmationAlertDialog = typedMemo((props: ConfirmationAlertDialogProps) => {
3233
const { t } = useTranslation();
3334

3435
const {
@@ -77,5 +78,3 @@ export const ConfirmationAlertDialog = memo((props: ConfirmationAlertDialogProps
7778
</AlertDialog>
7879
);
7980
});
80-
81-
ConfirmationAlertDialog.displayName = 'ConfirmationAlertDialog';

lib/components/button/button-group.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import type { ButtonGroupProps as ChakraButtonGroupProps, ComponentWithAs } from '@chakra-ui/react';
22
import { ButtonGroup as ChakraButtonGroup, forwardRef } from '@chakra-ui/react';
3-
import { memo } from 'react';
3+
4+
import { typedMemo } from '../../util';
45

56
export type ButtonGroupProps = ChakraButtonGroupProps;
67

7-
export const ButtonGroup: React.MemoExoticComponent<
8-
ComponentWithAs<ComponentWithAs<'div', ChakraButtonGroupProps>, ButtonGroupProps>
9-
> = memo(
8+
export const ButtonGroup: ComponentWithAs<ComponentWithAs<'div', ChakraButtonGroupProps>, ButtonGroupProps> = typedMemo(
109
forwardRef<ButtonGroupProps, typeof ChakraButtonGroup>(({ isAttached = true, ...rest }, ref) => {
1110
return <ChakraButtonGroup ref={ref} isAttached={isAttached} {...rest} />;
1211
})

lib/components/button/button.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
import type { ButtonProps as ChakraButtonProps, ComponentWithAs } from '@chakra-ui/react';
22
import { Button as ChakraButton, forwardRef } from '@chakra-ui/react';
33
import type { ReactNode } from 'react';
4-
import { memo } from 'react';
54

5+
import { typedMemo } from '../../util';
66
import { Tooltip } from '../tooltip/tooltip';
77

88
export type ButtonProps = ChakraButtonProps & {
99
isChecked?: boolean;
1010
tooltip?: ReactNode;
1111
};
1212

13-
export const Button: React.MemoExoticComponent<
14-
ComponentWithAs<ComponentWithAs<'button', ChakraButtonProps>, ButtonProps>
15-
> = memo(
13+
export const Button: ComponentWithAs<ComponentWithAs<'button', ChakraButtonProps>, ButtonProps> = typedMemo(
1614
forwardRef<ButtonProps, typeof ChakraButton>(({ isChecked, tooltip, children, ...rest }: ButtonProps, ref) => {
1715
if (tooltip) {
1816
return (

lib/components/button/icon-button.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
import type { ComponentWithAs, IconButtonProps as ChakraIconButtonProps } from '@chakra-ui/react';
22
import { forwardRef, IconButton as ChakraIconButton } from '@chakra-ui/react';
33
import type { ReactNode } from 'react';
4-
import { memo } from 'react';
54

5+
import { typedMemo } from '../../util';
66
import { Tooltip } from '../tooltip';
77

88
export type IconButtonProps = ChakraIconButtonProps & {
99
isChecked?: boolean;
1010
tooltip?: ReactNode;
1111
};
1212

13-
export const IconButton: React.MemoExoticComponent<
14-
ComponentWithAs<ComponentWithAs<'button', ChakraIconButtonProps>, IconButtonProps>
15-
> = memo(
13+
export const IconButton: ComponentWithAs<ComponentWithAs<'button', ChakraIconButtonProps>, IconButtonProps> = typedMemo(
1614
forwardRef<IconButtonProps, typeof ChakraIconButton>(({ isChecked, tooltip, ...rest }: IconButtonProps, ref) => {
1715
if (tooltip) {
1816
return (

lib/components/combobox/combobox-fallback.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import { memo } from 'react';
2-
1+
import { typedMemo } from '../../util';
32
import { Flex } from '../flex';
43
import { Text } from '../text';
54

65
export type ComboboxFallbackProps = {
76
label: string;
87
};
98

10-
export const ComboboxFallback = memo((props: ComboboxFallbackProps) => (
9+
export const ComboboxFallback = typedMemo((props: ComboboxFallbackProps) => (
1110
<Flex h={8} alignItems="center" justifyContent="center">
1211
<Text fontSize="sm" color="base.500">
1312
{props.label}

lib/components/combobox/combobox.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import type {
88
StylesConfig,
99
} from 'chakra-react-select';
1010
import { Select as ChakraReactSelect } from 'chakra-react-select';
11-
import { memo, useEffect, useMemo } from 'react';
11+
import { useEffect, useMemo } from 'react';
1212
export type {} from 'react-select/base';
1313

1414
import type { SystemStyleObject } from '@chakra-ui/styled-system';
1515

16+
import { typedMemo } from '../../util';
1617
import { CustomMenuListComponent } from './custom-menu-list';
1718
import type { ComboboxOption } from './custom-option';
1819
import { CustomOptionComponent } from './custom-option';
@@ -35,7 +36,7 @@ const components: SelectComponentsConfig<ComboboxOption, false, GroupBase<Combob
3536
MenuList: CustomMenuListComponent,
3637
};
3738

38-
export const Combobox = memo((props: ComboboxProps) => {
39+
export const Combobox = typedMemo((props: ComboboxProps) => {
3940
const { sx, selectRef, inputRef, ...rest } = props;
4041
const chakraStyles = useMemo<CustomChakraStylesConfig>(
4142
() => ({
@@ -84,4 +85,4 @@ export const Combobox = memo((props: ComboboxProps) => {
8485
);
8586
});
8687

87-
Combobox.displayName = 'InvSelect';
88+
Combobox.displayName = 'Combobox';

lib/components/combobox/custom-menu-list.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import { cloneDeep, merge } from 'lodash-es';
44
import type { UseOverlayScrollbarsParams } from 'overlayscrollbars-react';
55
import { useOverlayScrollbars } from 'overlayscrollbars-react';
66
import type { PropsWithChildren } from 'react';
7-
import { memo, useEffect, useRef, useState } from 'react';
7+
import { useEffect, useRef, useState } from 'react';
88

9+
import { typedMemo } from '../../util';
910
import { Box } from '../box';
1011
import { overlayScrollbarsParams } from '../shared/overlayscrollbars';
1112
import type { ComboboxOption } from './custom-option';
@@ -18,7 +19,7 @@ const overlayScrollbarsParamsOverrides: Partial<UseOverlayScrollbarsParams> = {
1819

1920
const osParams = merge(cloneDeep(overlayScrollbarsParams), overlayScrollbarsParamsOverrides);
2021

21-
const Scrollable = memo((props: PropsWithChildren<{ viewport: HTMLDivElement | null }>) => {
22+
const Scrollable = typedMemo((props: PropsWithChildren<{ viewport: HTMLDivElement | null }>) => {
2223
const { children, viewport } = props;
2324

2425
const targetRef = useRef<HTMLDivElement>(null);
@@ -45,7 +46,7 @@ const Scrollable = memo((props: PropsWithChildren<{ viewport: HTMLDivElement | n
4546

4647
Scrollable.displayName = 'Scrollable';
4748

48-
export const CustomMenuListComponent = memo(({ children, innerRef, ...other }: CustomMenuListProps) => {
49+
export const CustomMenuListComponent = typedMemo(({ children, innerRef, ...other }: CustomMenuListProps) => {
4950
const [viewport, setViewport] = useState<HTMLDivElement | null>(null);
5051

5152
useEffect(() => {

lib/components/combobox/custom-option.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { GroupBase, OptionBase, OptionProps } from 'chakra-react-select';
22
import { chakraComponents } from 'chakra-react-select';
33
import type { ReactNode } from 'react';
4-
import { memo } from 'react';
54

5+
import { typedMemo } from '../../util';
66
import { Flex } from '../flex';
77
import { Text } from '../text';
88
import { Tooltip } from '../tooltip';
@@ -19,7 +19,7 @@ export interface ComboboxOption extends OptionBase {
1919

2020
type CustomOptionProps = OptionProps<ComboboxOption, false, GroupBase<ComboboxOption>>;
2121

22-
export const CustomOptionComponent = memo(({ children, ...props }: CustomOptionProps) => {
22+
export const CustomOptionComponent = typedMemo(({ children, ...props }: CustomOptionProps) => {
2323
// On large lists, perf really takes a hit :/
2424
// This improves it drastically and doesn't seem to break anything...
2525
delete props.innerProps.onMouseMove;

0 commit comments

Comments
 (0)