# Handling Memory in Frontend Applications When building a frontend application that uses Mastra memory, it's important to only send the newest user message in each agent call. Mastra handles retrieving and injecting the necessary history. Sending the full history yourself will cause duplication. Here's a simplified example of how to handle this in a React application: ```tsx import { useState } from "react"; import { memoryAgent } from "./agents"; function ChatApp() { const [messages, setMessages] = useState([]); const [input, setInput] = useState(""); const handleSendMessage = async () => { // Add user message to UI setMessages([...messages, { role: "user", content: input }]); // Only send the newest message to the agent const response = await memoryAgent.stream(input, { resourceId: "user_123", threadId: "conversation_456", }); // Add agent response to UI setMessages([...messages, { role: "assistant", content: response }]); setInput(""); }; return (