|
1 |
| -import { useEffect, useMemo, useState } from 'react'; |
| 1 | +import { useMemo } from 'react'; |
2 | 2 |
|
3 | 3 | import { TFunction } from 'i18next';
|
4 | 4 | import type {
|
@@ -285,21 +285,19 @@ export const useLatestMessagePreview = <
|
285 | 285 | ? stringifyMessage(translatedLastMessage)
|
286 | 286 | : '';
|
287 | 287 |
|
288 |
| - const [readEvents, setReadEvents] = useState(true); |
| 288 | + const readEvents = useMemo(() => { |
| 289 | + if (!channelConfigExists) { |
| 290 | + return true; |
| 291 | + } |
| 292 | + const read_events = !channel.disconnected && !!channel?.id && channel.getConfig()?.read_events; |
| 293 | + if (typeof read_events !== 'boolean') { |
| 294 | + return true; |
| 295 | + } |
| 296 | + return read_events; |
| 297 | + }, [channelConfigExists, channel]); |
289 | 298 |
|
290 | 299 | const readStatus = getLatestMessageReadStatus(channel, client, translatedLastMessage, readEvents);
|
291 | 300 |
|
292 |
| - useEffect(() => { |
293 |
| - if (channelConfigExists) { |
294 |
| - const read_events = |
295 |
| - !channel.disconnected && !!channel?.id && channel.getConfig()?.read_events; |
296 |
| - if (typeof read_events === 'boolean') { |
297 |
| - setReadEvents(read_events); |
298 |
| - } |
299 |
| - } |
300 |
| - // eslint-disable-next-line react-hooks/exhaustive-deps |
301 |
| - }, [channelConfigExists]); |
302 |
| - |
303 | 301 | const pollId = lastMessage?.poll_id ?? '';
|
304 | 302 | const poll = client.polls.fromState(pollId);
|
305 | 303 | const pollState: LatestMessagePreviewSelectorReturnType =
|
|
0 commit comments