<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Goodluck Kalu-Nsi</title>
    <description>The latest articles on DEV Community by Goodluck Kalu-Nsi (@goodluck_kalunsi_1fb1e62).</description>
    <link>https://dev.to/goodluck_kalunsi_1fb1e62</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3931758%2Fc28c3ba5-e8dd-4ec5-a248-8693468dc308.jpg</url>
      <title>DEV Community: Goodluck Kalu-Nsi</title>
      <link>https://dev.to/goodluck_kalunsi_1fb1e62</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/goodluck_kalunsi_1fb1e62"/>
    <language>en</language>
    <item>
      <title>Building a Multi-Turn Chatbot with the Claude API in React</title>
      <dc:creator>Goodluck Kalu-Nsi</dc:creator>
      <pubDate>Thu, 14 May 2026 17:45:54 +0000</pubDate>
      <link>https://dev.to/goodluck_kalunsi_1fb1e62/building-a-multi-turn-chatbot-with-the-claude-api-in-react-2l8e</link>
      <guid>https://dev.to/goodluck_kalunsi_1fb1e62/building-a-multi-turn-chatbot-with-the-claude-api-in-react-2l8e</guid>
      <description>&lt;h1&gt;
  
  
  Building a Multi-Turn Chatbot with the Claude API in React
&lt;/h1&gt;

&lt;p&gt;When building RECORD.AI, I needed to manage multi-turn &lt;br&gt;
conversation state with the Anthropic Claude API. Here's &lt;br&gt;
how I structured it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Message Payload
&lt;/h2&gt;

&lt;p&gt;Claude expects messages in this format:&lt;br&gt;
[&lt;br&gt;
  { role: "user", content: "Hello" },&lt;br&gt;
  { role: "assistant", content: "Hi! How can I help?" },&lt;br&gt;
  { role: "user", content: "What is function calling?" }&lt;br&gt;
]&lt;/p&gt;

&lt;h2&gt;
  
  
  Managing State in React
&lt;/h2&gt;

&lt;p&gt;const [messages, setMessages] = useState([])&lt;/p&gt;

&lt;p&gt;const sendMessage = async (userInput) =&amp;gt; {&lt;br&gt;
  const newMessages = [...messages, { role: "user", content: userInput }]&lt;br&gt;
  setMessages(newMessages)&lt;/p&gt;

&lt;p&gt;const response = await fetch("&lt;a href="https://api.anthropic.com/v1/messages" rel="noopener noreferrer"&gt;https://api.anthropic.com/v1/messages&lt;/a&gt;", {&lt;br&gt;
    method: "POST",&lt;br&gt;
    headers: { "Content-Type": "application/json" },&lt;br&gt;
    body: JSON.stringify({&lt;br&gt;
      model: "claude-sonnet-4-20250514",&lt;br&gt;
      max_tokens: 1000,&lt;br&gt;
      messages: newMessages&lt;br&gt;
    })&lt;br&gt;
  })&lt;/p&gt;

&lt;p&gt;const data = await response.json()&lt;br&gt;
  const assistantReply = data.content[0].text&lt;br&gt;
  setMessages([...newMessages, { role: "assistant", content: assistantReply }])&lt;br&gt;
}&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Takeaway
&lt;/h2&gt;

&lt;p&gt;Always send the full conversation history on every request — &lt;br&gt;
Claude has no memory between calls.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>claude</category>
      <category>react</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
