Cache textWeight

This commit is contained in:
Lim Chee Aun 2023-06-14 11:14:49 +08:00
parent 50f0b38f42
commit cea4590686

View file

@ -12,7 +12,13 @@ import { decodeBlurHash } from 'fast-blurhash';
import mem from 'mem'; import mem from 'mem';
import pThrottle from 'p-throttle'; import pThrottle from 'p-throttle';
import { memo } from 'preact/compat'; 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 { InView } from 'react-intersection-observer';
import { useLongPress } from 'use-long-press'; import { useLongPress } from 'use-long-press';
import useResizeObserver from 'use-resize-observer'; import useResizeObserver from 'use-resize-observer';
@ -286,10 +292,14 @@ function Status({
const unauthInteractionErrorMessage = `Sorry, your current logged-in instance can't interact with this post from another instance.`; const unauthInteractionErrorMessage = `Sorry, your current logged-in instance can't interact with this post from another instance.`;
const textWeight = () => const textWeight = useCallback(
() =>
Math.max( Math.max(
Math.round((spoilerText.length + htmlContentLength(content)) / 140) || 1, Math.round((spoilerText.length + htmlContentLength(content)) / 140) ||
1, 1,
1,
),
[spoilerText, content],
); );
const createdDateText = niceDateTime(createdAtDate); const createdDateText = niceDateTime(createdAtDate);