chat-plugin-sdk/docs/api/use-watch-plugin-message.md
2023-11-22 15:31:48 +08:00

1.2 KiB

title description nav order group apiHeader
useWatchPluginMessage used to listen for plugin messages sent from LobeChat API 1
title order
Hooks 10
pkg
@lobehub/chat-plugin-sdk/client

useWatchPluginMessageThis is a React Hook encapsulating the Chat Plugin SDK, used to listen for plugin messages sent from LobeChat.

Syntax

const { data, loading } = useWatchPluginMessage<T>();

Examples

import { useWatchPluginMessage } from '@lobehub/chat-plugin-sdk/client';

const Demo = () => {
  const { data, loading } = useWatchPluginMessage();

  if (loading) {
    return <div>Loading...</div>;
  }

  return (
    <div>
      <h1>插件发送的消息数据:</h1>
      <pre>{JSON.stringify(data, null, 2)}</pre>
    </div>
  );
};

export default Demo;

Notes

  • Please ensure that useWatchPluginMessage is used within a React functional component.

Return Value Type Definition

Property Type Description
data T Data of the message sent by the plugin
loading boolean Indicates whether the data is currently being loaded