Skip to content

Commit

Permalink
fix: add missing dependencies to ChannelList hooks effects (#2525)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinCupela authored Oct 7, 2024
1 parent 8980016 commit 9cb8e47
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 24 deletions.
4 changes: 3 additions & 1 deletion src/components/ChannelList/ChannelList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,9 @@ const UnMemoizedChannelList = <
* For some events, inner properties on the channel will update but the shallow comparison will not
* force a re-render. Incrementing this dummy variable ensures the channel previews update.
*/
const forceUpdate = () => setChannelUpdateCount((count) => count + 1);
const forceUpdate = useCallback(() => setChannelUpdateCount((count) => count + 1), [
setChannelUpdateCount,
]);

const onSearch = useCallback((event: React.ChangeEvent<HTMLInputElement>) => {
if (!event.target.value) {
Expand Down
5 changes: 2 additions & 3 deletions src/components/ChannelList/hooks/useChannelDeletedListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const useChannelDeletedListener = <

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

// Remove the deleted channel from the list.s
// Remove the deleted channel from the list
channels.splice(channelIndex, 1);

return [...channels];
Expand All @@ -40,6 +40,5 @@ export const useChannelDeletedListener = <
return () => {
client.off('channel.deleted', handleEvent);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [customHandler]);
}, [client, customHandler, setChannels]);
};
3 changes: 1 addition & 2 deletions src/components/ChannelList/hooks/useChannelHiddenListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,5 @@ export const useChannelHiddenListener = <
return () => {
client.off('channel.hidden', handleEvent);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [customHandler]);
}, [client, customHandler, setChannels]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,5 @@ export const useChannelTruncatedListener = <
return () => {
client.off('channel.truncated', handleEvent);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [customHandler]);
}, [client, customHandler, forceUpdate, setChannels]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,5 @@ export const useChannelUpdatedListener = <
return () => {
client.off('channel.updated', handleEvent);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [customHandler]);
}, [client, customHandler, forceUpdate, setChannels]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,5 @@ export const useChannelVisibleListener = <
return () => {
client.off('channel.visible', handleEvent);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [customHandler]);
}, [client, customHandler, setChannels]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,5 @@ export const useConnectionRecoveredListener = <
return () => {
client.off('connection.recovered', handleEvent);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [client, forceUpdate]);
};
9 changes: 7 additions & 2 deletions src/components/ChannelList/hooks/useMessageNewListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export const useMessageNewListener = <
return () => {
client.off('message.new', handleEvent);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [lockChannelOrder]);
}, [
allowNewMessagesFromUnfilteredChannels,
client,
customHandler,
lockChannelOrder,
setChannels,
]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,5 @@ export const useNotificationAddedToChannelListener = <
return () => {
client.off('notification.added_to_channel', handleEvent);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [customHandler]);
}, [allowNewMessagesFromUnfilteredChannels, client, customHandler, setChannels]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,5 @@ export const useNotificationMessageNewListener = <
return () => {
client.off('notification.message_new', handleEvent);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [customHandler]);
}, [allowNewMessagesFromUnfilteredChannels, client, customHandler, setChannels]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,5 @@ export const useNotificationRemovedFromChannelListener = <
return () => {
client.off('notification.removed_from_channel', handleEvent);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [customHandler]);
}, [client, customHandler, setChannels]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,5 @@ export const useUserPresenceChangedListener = <
return () => {
client.off('user.presence.changed', handleEvent);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [client, setChannels]);
};

0 comments on commit 9cb8e47

Please sign in to comment.