Skip to content

Commit d28262a

Browse files
committed
Optimize recalculations
1 parent ff62df7 commit d28262a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/useTextAnalyzer.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@ function useTextAnalyzer({
1616
trimText = true,
1717
wordsPerMinute,
1818
}: TextAnalyzerOptions): TextAnalysisResult {
19-
const processedText = trimText ? text.trim() : text;
20-
const effectiveWPM = determineReadingSpeed(processedText, wordsPerMinute);
19+
const processedText = useMemo(() => {
20+
return trimText ? text.trim() : text;
21+
}, [text, trimText]);
22+
23+
const effectiveWPM = useMemo(() => {
24+
return determineReadingSpeed(processedText, wordsPerMinute);
25+
}, [processedText, wordsPerMinute]);
2126

2227
const analysisResult = useMemo(() => {
2328
return calculateStats({

0 commit comments

Comments
 (0)