@chainlit/react-client
package provides several React hooks to manage various aspects of your chat application seamlessly:
useChatSession
: Manages the chat session’s connection to the WebSocket server.useChatMessages
: Manages retrieval and rendering of chat messages.useChatData
: Accesses chat-related data and states.useChatInteract
: Provides methods to interact with the chat system.useAuth
: Handles authentication processes.useApi
: Simplifies API interactions with built-in support for data fetching and error handling.useChatSession
Hookconnect
: Establishes a connection to the WebSocket server.disconnect
: Disconnects from the WebSocket server.setChatProfile
: Sets the chat profile state.useChatMessages
HookuseChatMessages
hook provides access to the current chat messages, the first user interaction, and the active thread ID within your React application. It leverages Recoil for state management, ensuring that your components reactively update in response to state changes.
threadId
(string | undefined
):messages
(IStep[]
):firstInteraction
(string | undefined
):useChatData
HookuseChatData
hook offers comprehensive access to various chat-related states and data within your React application.
actions
(IAction[]
)askUser
(IAsk | undefined
)chatSettingsValue
(any
)connected
(boolean
)disabled
(boolean
)error
(boolean | undefined
)loading
(boolean
)tasklists
(ITasklistElement[]
)useChatInteract
HookuseChatInteract
hook provides a comprehensive set of methods to interact with the chat system within your React application.
sendMessage
replyMessage
clear
uploadFile
callAction
startAudioStream
sendAudioChunk
stopTask
useAuth
HookuseAuth
hook manages authentication within your React application, providing functionalities like user sessions and token management.
authConfig
user
accessToken
isLoading
logout
useApi
HookuseApi
hook simplifies data fetching and error handling using SWR.