Skip to content

Catch errors when sendJsonMessage #267

Description

@BLazzeD21
const sendMessageSocket = useCallback(
  (message: string): void => {
    if (readyState === ReadyState.OPEN && isSelectedChat) {
      sendJsonMessage({
          order_id: selectedChat.order_id,
          from_user_id: userID,
          to_user_id: selectedChat.user_id,
          text: message,
        }
        as SocketMessageSent);
      const newMessage = {
        id: `temp-${Date.now()}`,
        order_id: selectedChat.order_id,
        from_user_id: userID,
        to_user_id: selectedChat.user_id,
        text: message,
        image: null,
        created_at: getUTCDate(),
        is_read: false,
      }
      as OrderMessage;
      setLocalMessages((prev) => [newMessage, ...prev]);
    }
  },
  [selectedChat, readyState, userID],
);

How can I track the success of sending data via sendJsonMessage, for example in this function or in hook options?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions