Skip to content

Commit 863f6cd

Browse files
committed
perf: sendMessage memoization from top level ctx
1 parent 3e49044 commit 863f6cd

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

package/src/components/Channel/Channel.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1758,6 +1758,11 @@ const ChannelWithContext = <
17581758
const sendMessageRef =
17591759
useRef<InputMessageInputContextValue<StreamChatGenerics>['sendMessage']>(sendMessage);
17601760
sendMessageRef.current = sendMessage;
1761+
const sendMessageStable = useCallback<
1762+
InputMessageInputContextValue<StreamChatGenerics>['sendMessage']
1763+
>((...args) => {
1764+
return sendMessageRef.current(...args);
1765+
}, []);
17611766

17621767
const inputMessageInputContext = useCreateInputMessageInputContext<StreamChatGenerics>({
17631768
additionalTextInputProps,
@@ -1811,7 +1816,7 @@ const ChannelWithContext = <
18111816
quotedMessage,
18121817
SendButton,
18131818
sendImageAsync,
1814-
sendMessage: (...args) => sendMessageRef.current(...args),
1819+
sendMessage: sendMessageStable,
18151820
SendMessageDisallowedIndicator,
18161821
setInputRef,
18171822
setQuotedMessageState,

0 commit comments

Comments
 (0)