React Chat - Render Images
To render an image in a Chat, set the message type to "image" and specify the src field with the image URL. In the following example, AI sends a message with the "imageResponse" type, which is then converted into an image in Chat.
NOTE
Chat displays either images or text in a single message. Specify messageTemplate to display custom messages.
App.tsx
- export default function App() {
- const handleAIResponse() => {
- if (aiResponse.type === "imageResponse") {
- const imageMessage = ({
- type: "image",
- src: aiResponse.imageUrl,
- author: "bot"
- });
- }
- setMessages((prevMessages) => [...prevMessages, imageMessage]);
- };
- }