refactor: streamline readSet initialization in useTeamMessagesRead hook
- Simplified the initialization of the readSet in the `useTeamMessagesRead` hook by consolidating the logic into a single useMemo call. - Removed unnecessary useEffect for setting the readSet, improving performance and readability.
This commit is contained in:
parent
dbb418ad64
commit
bdb1f5ccd1
1 changed files with 4 additions and 14 deletions
|
|
@ -10,20 +10,10 @@ export function useTeamMessagesRead(teamName: string): {
|
|||
markRead: (messageKey: string) => void;
|
||||
} {
|
||||
const [version, setVersion] = useState(0);
|
||||
const readSet = useMemo(
|
||||
() => {
|
||||
if (version < 0) return new Set<string>();
|
||||
return teamName ? getReadSetStorage(teamName) : new Set<string>();
|
||||
},
|
||||
[teamName, version]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!teamName) return;
|
||||
const next = getReadSetStorage(teamName);
|
||||
const t = setTimeout(() => setReadSet(next), 0);
|
||||
return () => clearTimeout(t);
|
||||
}, [teamName]);
|
||||
const readSet = useMemo(() => {
|
||||
if (version < 0) return new Set<string>();
|
||||
return teamName ? getReadSetStorage(teamName) : new Set<string>();
|
||||
}, [teamName, version]);
|
||||
|
||||
const markRead = useCallback(
|
||||
(messageKey: string) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue