chore: memoize components (#607)
This commit is contained in:
parent
906d7d34da
commit
3df0fd4c0f
6 changed files with 123 additions and 53 deletions
|
|
@ -5,6 +5,7 @@ import { Overview } from './overview';
|
|||
import { UIBlock } from './block';
|
||||
import { Dispatch, memo, SetStateAction } from 'react';
|
||||
import { Vote } from '@/lib/db/schema';
|
||||
import equal from 'fast-deep-equal';
|
||||
|
||||
interface MessagesProps {
|
||||
chatId: string;
|
||||
|
|
@ -74,15 +75,11 @@ function PureMessages({
|
|||
);
|
||||
}
|
||||
|
||||
function areEqual(prevProps: MessagesProps, nextProps: MessagesProps) {
|
||||
if (
|
||||
prevProps.block.status === 'streaming' &&
|
||||
nextProps.block.status === 'streaming'
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
export const Messages = memo(PureMessages, (prevProps, nextProps) => {
|
||||
if (prevProps.isLoading !== nextProps.isLoading) return false;
|
||||
if (prevProps.isLoading && nextProps.isLoading) return false;
|
||||
if (prevProps.messages.length !== nextProps.messages.length) return false;
|
||||
if (!equal(prevProps.votes, nextProps.votes)) return false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export const Messages = memo(PureMessages, areEqual);
|
||||
return true;
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue