Skip to content

Commit

Permalink
Merge pull request #86 from bshelkhonov/fix-dom-rebuild
Browse files Browse the repository at this point in the history
Memoize components in useTypographyCellComponents to fix DOM rebuild
  • Loading branch information
mainsmirnov authored Nov 27, 2024
2 parents 69993b8 + ad4ae23 commit ba0cc3b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/components/Blocks/Cell/hooks/useTypographyCellComponents.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use client';

import { useCallback } from 'react';

import { usePlatform } from 'hooks/usePlatform';

import { Caption } from 'components/Typography/Caption/Caption';
Expand All @@ -11,21 +13,21 @@ export const useTypographyCellComponents = () => {
const platform = usePlatform();
const isIOS = platform === 'ios';

const Title = (props: TypographyProps) => {
const Title = useCallback((props: TypographyProps) => {
if (isIOS) {
return <Text {...props} />;
}

return <Subheadline level="1" {...props} />;
};
}, [isIOS]);

const Description = (props: TypographyProps) => {
const Description = useCallback((props: TypographyProps) => {
if (isIOS) {
return <Caption {...props} />;
}

return <Subheadline level="2" {...props} />;
};
}, [isIOS]);

return {
Title,
Expand Down

0 comments on commit ba0cc3b

Please sign in to comment.