fix: memoize components and improve performance (#579)

This commit is contained in:
Jeremy 2024-12-03 17:49:38 +03:00 committed by GitHub
parent a13368cfcd
commit e839007580
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 453 additions and 232 deletions

View file

@ -1,4 +1,4 @@
import type { SetStateAction } from 'react';
import { memo, type SetStateAction } from 'react';
import type { UIBlock } from './block';
import { FileIcon, LoaderIcon, MessageIcon, PencilEditIcon } from './icons';
@ -28,7 +28,7 @@ interface DocumentToolResultProps {
setBlock: (value: SetStateAction<UIBlock>) => void;
}
export function DocumentToolResult({
function PureDocumentToolResult({
type,
result,
setBlock,
@ -73,17 +73,15 @@ export function DocumentToolResult({
);
}
export const DocumentToolResult = memo(PureDocumentToolResult, () => true);
interface DocumentToolCallProps {
type: 'create' | 'update' | 'request-suggestions';
args: { title: string };
setBlock: (value: SetStateAction<UIBlock>) => void;
}
export function DocumentToolCall({
type,
args,
setBlock,
}: DocumentToolCallProps) {
function PureDocumentToolCall({ type, args, setBlock }: DocumentToolCallProps) {
return (
<button
type="button"
@ -125,3 +123,5 @@ export function DocumentToolCall({
</button>
);
}
export const DocumentToolCall = memo(PureDocumentToolCall, () => true);