From cea4590686e94fa9d56d995d492cc9b8de11b870 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Wed, 14 Jun 2023 11:14:49 +0800 Subject: [PATCH] Cache textWeight --- src/components/status.jsx | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/components/status.jsx b/src/components/status.jsx index ffde35e4..60b4f7e7 100644 --- a/src/components/status.jsx +++ b/src/components/status.jsx @@ -12,7 +12,13 @@ import { decodeBlurHash } from 'fast-blurhash'; import mem from 'mem'; import pThrottle from 'p-throttle'; import { memo } from 'preact/compat'; -import { useEffect, useMemo, useRef, useState } from 'preact/hooks'; +import { + useCallback, + useEffect, + useMemo, + useRef, + useState, +} from 'preact/hooks'; import { InView } from 'react-intersection-observer'; import { useLongPress } from 'use-long-press'; import useResizeObserver from 'use-resize-observer'; @@ -286,11 +292,15 @@ function Status({ const unauthInteractionErrorMessage = `Sorry, your current logged-in instance can't interact with this post from another instance.`; - const textWeight = () => - Math.max( - Math.round((spoilerText.length + htmlContentLength(content)) / 140) || 1, - 1, - ); + const textWeight = useCallback( + () => + Math.max( + Math.round((spoilerText.length + htmlContentLength(content)) / 140) || + 1, + 1, + ), + [spoilerText, content], + ); const createdDateText = niceDateTime(createdAtDate); const editedDateText = editedAt && niceDateTime(editedAtDate);