Skip to content

Commit 9cb8e47

Browse files
authored
fix: add missing dependencies to ChannelList hooks effects (#2525)
1 parent 8980016 commit 9cb8e47

12 files changed

+21
-24
lines changed

src/components/ChannelList/ChannelList.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,9 @@ const UnMemoizedChannelList = <
252252
* For some events, inner properties on the channel will update but the shallow comparison will not
253253
* force a re-render. Incrementing this dummy variable ensures the channel previews update.
254254
*/
255-
const forceUpdate = () => setChannelUpdateCount((count) => count + 1);
255+
const forceUpdate = useCallback(() => setChannelUpdateCount((count) => count + 1), [
256+
setChannelUpdateCount,
257+
]);
256258

257259
const onSearch = useCallback((event: React.ChangeEvent<HTMLInputElement>) => {
258260
if (!event.target.value) {

src/components/ChannelList/hooks/useChannelDeletedListener.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const useChannelDeletedListener = <
2727

2828
if (channelIndex < 0) return [...channels];
2929

30-
// Remove the deleted channel from the list.s
30+
// Remove the deleted channel from the list
3131
channels.splice(channelIndex, 1);
3232

3333
return [...channels];
@@ -40,6 +40,5 @@ export const useChannelDeletedListener = <
4040
return () => {
4141
client.off('channel.deleted', handleEvent);
4242
};
43-
// eslint-disable-next-line react-hooks/exhaustive-deps
44-
}, [customHandler]);
43+
}, [client, customHandler, setChannels]);
4544
};

src/components/ChannelList/hooks/useChannelHiddenListener.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,5 @@ export const useChannelHiddenListener = <
3939
return () => {
4040
client.off('channel.hidden', handleEvent);
4141
};
42-
// eslint-disable-next-line react-hooks/exhaustive-deps
43-
}, [customHandler]);
42+
}, [client, customHandler, setChannels]);
4443
};

src/components/ChannelList/hooks/useChannelTruncatedListener.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,5 @@ export const useChannelTruncatedListener = <
3535
return () => {
3636
client.off('channel.truncated', handleEvent);
3737
};
38-
// eslint-disable-next-line react-hooks/exhaustive-deps
39-
}, [customHandler]);
38+
}, [client, customHandler, forceUpdate, setChannels]);
4039
};

src/components/ChannelList/hooks/useChannelUpdatedListener.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,5 @@ export const useChannelUpdatedListener = <
5050
return () => {
5151
client.off('channel.updated', handleEvent);
5252
};
53-
// eslint-disable-next-line react-hooks/exhaustive-deps
54-
}, [customHandler]);
53+
}, [client, customHandler, forceUpdate, setChannels]);
5554
};

src/components/ChannelList/hooks/useChannelVisibleListener.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,5 @@ export const useChannelVisibleListener = <
3939
return () => {
4040
client.off('channel.visible', handleEvent);
4141
};
42-
// eslint-disable-next-line react-hooks/exhaustive-deps
43-
}, [customHandler]);
42+
}, [client, customHandler, setChannels]);
4443
};

src/components/ChannelList/hooks/useConnectionRecoveredListener.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,5 @@ export const useConnectionRecoveredListener = <
2323
return () => {
2424
client.off('connection.recovered', handleEvent);
2525
};
26-
// eslint-disable-next-line react-hooks/exhaustive-deps
27-
}, []);
26+
}, [client, forceUpdate]);
2827
};

src/components/ChannelList/hooks/useMessageNewListener.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ export const useMessageNewListener = <
4747
return () => {
4848
client.off('message.new', handleEvent);
4949
};
50-
// eslint-disable-next-line react-hooks/exhaustive-deps
51-
}, [lockChannelOrder]);
50+
}, [
51+
allowNewMessagesFromUnfilteredChannels,
52+
client,
53+
customHandler,
54+
lockChannelOrder,
55+
setChannels,
56+
]);
5257
};

src/components/ChannelList/hooks/useNotificationAddedToChannelListener.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,5 @@ export const useNotificationAddedToChannelListener = <
4747
return () => {
4848
client.off('notification.added_to_channel', handleEvent);
4949
};
50-
// eslint-disable-next-line react-hooks/exhaustive-deps
51-
}, [customHandler]);
50+
}, [allowNewMessagesFromUnfilteredChannels, client, customHandler, setChannels]);
5251
};

src/components/ChannelList/hooks/useNotificationMessageNewListener.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,5 @@ export const useNotificationMessageNewListener = <
4040
return () => {
4141
client.off('notification.message_new', handleEvent);
4242
};
43-
// eslint-disable-next-line react-hooks/exhaustive-deps
44-
}, [customHandler]);
43+
}, [allowNewMessagesFromUnfilteredChannels, client, customHandler, setChannels]);
4544
};

0 commit comments

Comments
 (0)