feat(ui): memoize all components

This commit is contained in:
psychedelicious
2023-12-29 14:05:56 +11:00
committed by Kent Keirsey
parent ca4b8e65c1
commit 56527da73e
65 changed files with 1165 additions and 970 deletions

View File

@@ -2,28 +2,32 @@ import { forwardRef, Textarea as ChakraTextarea } from '@chakra-ui/react';
import { useGlobalModifiersSetters } from 'common/hooks/useGlobalModifiers';
import { stopPastePropagation } from 'common/util/stopPastePropagation';
import type { KeyboardEvent } from 'react';
import { useCallback } from 'react';
import { memo, useCallback } from 'react';
import type { InvTextareaProps } from './types';
export const InvTextarea = forwardRef<InvTextareaProps, typeof ChakraTextarea>(
(props: InvTextareaProps, ref) => {
const { ...rest } = props;
const { setShift } = useGlobalModifiersSetters();
const onKeyUpDown = useCallback(
(e: KeyboardEvent<HTMLTextAreaElement>) => {
setShift(e.shiftKey);
},
[setShift]
);
return (
<ChakraTextarea
ref={ref}
onPaste={stopPastePropagation}
onKeyUp={onKeyUpDown}
onKeyDown={onKeyUpDown}
{...rest}
/>
);
}
export const InvTextarea = memo(
forwardRef<InvTextareaProps, typeof ChakraTextarea>(
(props: InvTextareaProps, ref) => {
const { ...rest } = props;
const { setShift } = useGlobalModifiersSetters();
const onKeyUpDown = useCallback(
(e: KeyboardEvent<HTMLTextAreaElement>) => {
setShift(e.shiftKey);
},
[setShift]
);
return (
<ChakraTextarea
ref={ref}
onPaste={stopPastePropagation}
onKeyUp={onKeyUpDown}
onKeyDown={onKeyUpDown}
{...rest}
/>
);
}
)
);
InvTextarea.displayName = 'InvTextarea';