refactor: 清理代码注释并优化组件结构
- 在 useQrCode.ts 中移除多余的注释,简化代码逻辑。 - 在 DataPreview.tsx 和 FieldEditor.tsx 中删除不必要的注释,提升可读性。 - 在 format.ts 和 jsonToToml.ts 中更新注释内容,确保准确性。
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useCallback, useState } from 'react';
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { getTextStats, type TextStats } from '@/utils/textStatistics';
|
||||
import { useContextMenuData } from '@/utils/useContextMenuData';
|
||||
|
||||
@@ -10,6 +10,12 @@ export interface UseTextStatisticsReturn {
|
||||
|
||||
export function useTextStatistics(): UseTextStatisticsReturn {
|
||||
const [text, setText] = useState('');
|
||||
const [debouncedText, setDebouncedText] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
const handle = setTimeout(() => setDebouncedText(text), 200);
|
||||
return () => clearTimeout(handle);
|
||||
}, [text]);
|
||||
|
||||
const handleContextMenuData = useCallback((payload: string) => {
|
||||
setText(payload);
|
||||
@@ -17,7 +23,7 @@ export function useTextStatistics(): UseTextStatisticsReturn {
|
||||
|
||||
useContextMenuData({ featureKey: 'textStatistics', onData: handleContextMenuData });
|
||||
|
||||
const stats = getTextStats(text);
|
||||
const stats = useMemo(() => getTextStats(debouncedText), [debouncedText]);
|
||||
|
||||
return { text, stats, setText };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user