The proposed approach offers substantial improvements in terms of modularity and readability. It intends to split the main Chat component into several smaller functional parts. It starts by moving the API call functions getAgentReply and clearChatHistory to a new file named src/hooks/chatApi.ts. Additionally, the useMutation calls are moved to chatApi.ts too. Furthermore, the state management of messages, user inputs, along with handleScroll and submit functionality are moved into a new hook src/hooks/useMessages.ts. Lastly, the smaller components UserMessage and BotMessage are each moved to new separate files.
The proposed approach offers substantial improvements in terms of modularity and readability. It intends to split the main Chat component into several smaller functional parts. It starts by moving the API call functions
getAgentReply
andclearChatHistory
to a new file namedsrc/hooks/chatApi.ts
. Additionally, theuseMutation
calls are moved tochatApi.ts
too. Furthermore, the state management of messages, user inputs, along with handleScroll and submit functionality are moved into a new hooksrc/hooks/useMessages.ts
. Lastly, the smaller componentsUserMessage
andBotMessage
are each moved to new separate files.