<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Rahul kumar on Medium]]></title>
        <description><![CDATA[Stories by Rahul kumar on Medium]]></description>
        <link>https://medium.com/@rahulkuma?source=rss-c92746bd5961------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*QXkK0lP8Ut_ln3EULzBmLA.png</url>
            <title>Stories by Rahul kumar on Medium</title>
            <link>https://medium.com/@rahulkuma?source=rss-c92746bd5961------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 15:00:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rahulkuma/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[From One Tool to an Agent-Ready React App: Building a Practical WebMCP Workflow]]></title>
            <link>https://medium.com/@rahulkuma/from-one-tool-to-an-agent-ready-react-app-building-a-practical-webmcp-workflow-ca085b94b9ab?source=rss-c92746bd5961------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca085b94b9ab</guid>
            <category><![CDATA[website]]></category>
            <category><![CDATA[mcps]]></category>
            <category><![CDATA[web-mcp]]></category>
            <dc:creator><![CDATA[Rahul kumar]]></dc:creator>
            <pubDate>Wed, 28 Oct 2026 09:21:14 GMT</pubDate>
            <atom:updated>2026-10-28T09:21:14.756Z</atom:updated>
            <content:encoded><![CDATA[<h3>Part 2 of The Agentic Web series</h3><p>In the first part of this series, I wanted to answer a fairly simple question:</p><blockquote><strong><em>Can a React application expose its functionality directly to an AI agent instead of making the agent figure everything out from the UI?</em></strong></blockquote><p>To explore that, I built a small flight-search application and exposed a searchFlights function as a WebMCP tool.</p><p>It was deliberately simple.</p><p>The application had one meaningful operation:</p><pre>searchFlights()</pre><p>The browser could discover the tool, understand its input schema, and execute it.</p><p>That was enough to understand the basic WebMCP model:</p><pre>Register a tool<br>      ↓<br>Browser discovers it<br>      ↓<br>Agent can understand the capability<br>      ↓<br>Tool is executed<br>      ↓<br>Application returns a result</pre><p>But after getting that working, I had another question.</p><p><strong>What happens when the application has more than one tool?</strong></p><p>Real applications don’t have one operation.</p><p>They have workflows.</p><p>One operation might retrieve information. Another might depend on the result of the first. Some operations are harmless and read-only. Others change application state. Some should only be available after login. And some should absolutely require confirmation before an agent is allowed to execute them.</p><p>That’s where the WebMCP idea started becoming much more interesting to me.</p><p>So for my second experiment, I wanted to build something that felt a little closer to a real application.</p><p>Not production-sized.</p><p>Just complicated enough to expose the architectural questions that a single-tool demo hides.</p><h3>A different example this time: a support desk</h3><p>Instead of continuing with the flight-search example, let’s build a small customer-support application.</p><p>Imagine a page where a user can:</p><ul><li>search the knowledge base,</li><li>open a support article,</li><li>check an existing ticket,</li><li>and create a new support ticket.</li></ul><p>A normal React interface might look roughly like this:</p><pre>-------------------------------------------------</pre><pre>Support Desk</pre><pre>What can we help you with?</pre><pre>[ Payment keeps failing                    ]</pre><pre>[ Search ]</pre><pre>-------------------------------------------------</pre><pre>Suggested Articles</pre><pre>Troubleshooting failed payments<br>Card verification issues<br>Payment methods we support</pre><pre>-------------------------------------------------</pre><pre>My Tickets</pre><pre>#1042    Unable to login              Open<br>#1031    Payment verification         Resolved</pre><pre>-------------------------------------------------</pre><pre>[ Create Ticket ]</pre><pre>-------------------------------------------------</pre><p>There is nothing particularly agentic about this application.</p><p>A human can use it normally.</p><p>That’s actually important.</p><p>I don’t want to build a separate application specifically for AI agents. I want to understand how an existing web application could expose some of its capabilities to an agent without duplicating all of its business logic.</p><p>So let’s start exactly where I would start with any React application.</p><p>With the application logic.</p><h3>1. Build the application before thinking about WebMCP</h3><p>Let’s create some mock support articles.</p><pre>const articles = [<br>  {<br>    id: &#39;kb-101&#39;,<br>    title: &#39;Troubleshooting failed payments&#39;,<br>    tags: [&#39;payment&#39;, &#39;card&#39;, &#39;checkout&#39;],<br>    content:<br>      &#39;Start by checking that the billing address matches the address registered with the card issuer.&#39;,<br>  },<br>  {<br>    id: &#39;kb-102&#39;,<br>    title: &#39;Card verification issues&#39;,<br>    tags: [&#39;payment&#39;, &#39;verification&#39;, &#39;card&#39;],<br>    content:<br>      &#39;Some banks require additional verification before approving an online payment.&#39;,<br>  },<br>  {<br>    id: &#39;kb-103&#39;,<br>    title: &#39;Resetting your password&#39;,<br>    tags: [&#39;account&#39;, &#39;password&#39;, &#39;login&#39;],<br>    content:<br>      &#39;Use the Forgot Password option on the sign-in page to reset your password.&#39;,<br>  },<br>];</pre><p>Then create an ordinary service function:</p><pre>export function searchKnowledgeBase(query) {<br>  const term = query.trim().toLowerCase();<br><br>  return articles.filter((article) =&gt; {<br>    const searchableText = [<br>      article.title,<br>      ...article.tags,<br>      article.content,<br>    ]<br>      .join(&#39; &#39;)<br>      .toLowerCase();<br><br>    return searchableText.includes(term);<br>  });<br>}</pre><p>Again, there is nothing WebMCP-specific here.</p><p>Our React component could call this function:</p><pre>function SupportSearch() {<br>  const [query, setQuery] = useState(&#39;&#39;);<br>  const [results, setResults] = useState([]);<br><br>  const handleSearch = () =&gt; {<br>    setResults(searchKnowledgeBase(query));<br>  };<br><br>  return (<br>    &lt;&gt;<br>      &lt;input<br>        value={query}<br>        onChange={(event) =&gt;<br>          setQuery(event.target.value)<br>        }<br>      /&gt;<br><br>      &lt;button onClick={handleSearch}&gt;<br>        Search<br>      &lt;/button&gt;<br><br>      {results.map((article) =&gt; (<br>        &lt;div key={article.id}&gt;<br>          {article.title}<br>        &lt;/div&gt;<br>      ))}<br>    &lt;/&gt;<br>  );<br>}</pre><p>So far, this is just React.</p><p>And I think keeping this separation is important.</p><p>The business capability is:</p><pre>searchKnowledgeBase()</pre><p>The React interface is simply <strong>one consumer</strong> of that capability.</p><p>WebMCP will become another.</p><p>That gives us an architecture like this:</p><pre>searchKnowledgeBase()<br>                              ↑<br>                 ┌────────────┴────────────┐<br>                 │                         │<br>             React UI                 WebMCP Tool<br>                 ↑                         ↑<br>                 │                         │<br>               Human                   AI Agent</pre><p>I like this model because WebMCP doesn’t become the center of the application.</p><p>It sits at the boundary.</p><h3>2. Our first tool: search the knowledge base</h3><p>Let’s expose our existing function as a WebMCP tool.</p><pre>const searchKnowledgeBaseTool = {<br>  name: &#39;searchKnowledgeBase&#39;,<br><br>  description:<br>    &#39;Search support articles for information related to a user problem.&#39;,<br><br>  inputSchema: {<br>    type: &#39;object&#39;,<br><br>    properties: {<br>      query: {<br>        type: &#39;string&#39;,<br>        description:<br>          &#39;A short description of the issue the user needs help with.&#39;,<br>      },<br>    },<br><br>    required: [&#39;query&#39;],<br>  },<br><br>  annotations: {<br>    readOnlyHint: true,<br>  },<br><br>  execute: async ({ query }) =&gt; {<br>    const results =<br>      searchKnowledgeBase(query);<br><br>    return JSON.stringify({<br>      count: results.length,<br><br>      articles: results.map((article) =&gt; ({<br>        id: article.id,<br>        title: article.title,<br>      })),<br>    });<br>  },<br>};</pre><p>At first glance, this looks very similar to the searchFlights tool from Part 1.</p><p>But now that we’re going to have multiple tools, some of these details become more important.</p><p>Especially the description.</p><h3>3. Tool descriptions aren’t just documentation</h3><p>As developers, we’re used to descriptions and comments being mostly for other developers.</p><p>If I write:</p><pre>description: &#39;Search stuff&#39;</pre><p>JavaScript doesn’t care.</p><p>The function still works.</p><p>But when an agent is choosing between multiple tools, the description starts becoming part of the interface.</p><p>Imagine our application eventually exposes:</p><pre>searchKnowledgeBase<br>getArticle<br>getTicketStatus<br>createSupportTicket</pre><p>Now the agent has to decide which one is appropriate for the user’s request.</p><p>If the user says:</p><blockquote><em>“My card payment keeps failing. Is there anything that can help?”</em></blockquote><p>then this:</p><pre>description: &#39;Search stuff&#39;</pre><p>doesn’t provide much information.</p><p>This is much better:</p><pre>description:<br>  &#39;Search support articles for information related to a user problem.&#39;</pre><p>The same applies to parameters.</p><p>This:</p><pre>query: {<br>  type: &#39;string&#39;,<br>}</pre><p>technically describes the input.</p><p>But:</p><pre>query: {<br>  type: &#39;string&#39;,<br>  description:<br>    &#39;A short description of the issue the user needs help with.&#39;,<br>}</pre><p>gives the agent much more context.</p><p>That was one of the first things that changed in how I thought about tools.</p><p><strong>Tool design isn’t only function design.</strong></p><p>Names, descriptions, schemas and boundaries are all part of the contract presented to the agent.</p><p>It starts feeling surprisingly similar to designing a good API.</p><h3>4. One tool isn’t really a workflow</h3><p>Search gives us article titles, but suppose the user wants to read one.</p><p>We could make searchKnowledgeBase() return the entire article.</p><p>But let’s resist that for a moment.</p><p>Instead, we’ll introduce another capability:</p><pre>getArticle()</pre><p>Its job is very specific:</p><blockquote><em>Given an article ID, return the article.</em></blockquote><pre>const getArticleTool = {<br>  name: &#39;getArticle&#39;,<br><br>  description:<br>    &#39;Get the full content of a support article using an article ID returned by the knowledge-base search.&#39;,<br><br>  inputSchema: {<br>    type: &#39;object&#39;,<br><br>    properties: {<br>      articleId: {<br>        type: &#39;string&#39;,<br>        description:<br>          &#39;The ID of the support article to retrieve.&#39;,<br>      },<br>    },<br><br>    required: [&#39;articleId&#39;],<br>  },<br><br>  annotations: {<br>    readOnlyHint: true,<br>  },<br><br>  execute: async ({ articleId }) =&gt; {<br>    const article = articles.find(<br>      (item) =&gt; item.id === articleId<br>    );<br><br>    if (!article) {<br>      return JSON.stringify({<br>        success: false,<br>        error: {<br>          code: &#39;ARTICLE_NOT_FOUND&#39;,<br>          message:<br>            `No support article was found for ${articleId}.`,<br>        },<br>      });<br>    }<br><br>    return JSON.stringify({<br>      success: true,<br>      article,<br>    });<br>  },<br>};</pre><p>Now we have something we didn’t have in Part 1:</p><pre>searchKnowledgeBase()<br>          │<br>          │ returns article ID<br>          ▼<br>     getArticle()</pre><p>The output of one capability can help an agent use another capability.</p><p>That’s our first small <strong>tool chain</strong>.</p><h3>5. Why not just create one giant tool?</h3><p>At this point I had an obvious thought.</p><p>Why not create:</p><pre>findAndReadSupportArticle()</pre><p>It could search, pick an article, fetch it and return everything in one call.</p><p>For this tiny example, that might even work.</p><p>But now imagine the application growing.</p><p>Maybe another workflow needs search results but doesn’t need the full article.</p><p>Maybe the UI needs getArticle() independently.</p><p>Maybe later we want:</p><pre>recommendArticles()</pre><p>or:</p><pre>bookmarkArticle()</pre><p>If every tool tries to represent an entire user journey, the tools become large and overlapping very quickly.</p><p>Instead, I prefer thinking about them as <strong>small business capabilities that can be composed</strong>.</p><p>So rather than:</p><pre>solveCustomerProblem()</pre><p>we expose:</p><pre>searchKnowledgeBase()<br>getArticle()<br>getTicketStatus()<br>createSupportTicket()</pre><p>The agent can reason about how to combine those capabilities.</p><p>This is very similar to good API design:</p><blockquote><em>Give consumers useful primitives with clear responsibilities instead of one endpoint that tries to do everything.</em></blockquote><h3>6. Adding ticket status</h3><p>Let’s introduce another read operation.</p><p>Our mock tickets:</p><pre>const tickets = [<br>  {<br>    id: &#39;TKT-1042&#39;,<br>    subject: &#39;Unable to login&#39;,<br>    status: &#39;OPEN&#39;,<br>    updatedAt: &#39;2026-10-08T10:30:00Z&#39;,<br>  },<br>  {<br>    id: &#39;TKT-1031&#39;,<br>    subject: &#39;Payment verification&#39;,<br>    status: &#39;RESOLVED&#39;,<br>    updatedAt: &#39;2026-10-05T08:15:00Z&#39;,<br>  },<br>];</pre><p>Service:</p><pre>export function getTicketStatus(ticketId) {<br>  return tickets.find(<br>    (ticket) =&gt; ticket.id === ticketId<br>  );<br>}</pre><p>Tool:</p><pre>const getTicketStatusTool = {<br>  name: &#39;getTicketStatus&#39;,<br><br>  description:<br>    &#39;Check the current status of an existing support ticket.&#39;,<br><br>  inputSchema: {<br>    type: &#39;object&#39;,<br><br>    properties: {<br>      ticketId: {<br>        type: &#39;string&#39;,<br>        description:<br>          &#39;The support ticket ID, for example TKT-1042.&#39;,<br>      },<br>    },<br><br>    required: [&#39;ticketId&#39;],<br>  },<br><br>  annotations: {<br>    readOnlyHint: true,<br>  },<br><br>  execute: async ({ ticketId }) =&gt; {<br>    const ticket =<br>      getTicketStatus(ticketId);<br><br>    if (!ticket) {<br>      return JSON.stringify({<br>        success: false,<br>        error: {<br>          code: &#39;TICKET_NOT_FOUND&#39;,<br>          message: &#39;Ticket not found.&#39;,<br>        },<br>      });<br>    }<br><br>    return JSON.stringify({<br>      success: true,<br>      ticket,<br>    });<br>  },<br>};</pre><p>Our agent-facing application now has three capabilities:</p><pre>searchKnowledgeBase()   → READ<br>getArticle()            → READ<br>getTicketStatus()       → READ</pre><p>So far everything is relatively safe.</p><p>We’re retrieving information.</p><p>Then things get more interesting.</p><h3>7. Let’s let the agent change something</h3><p>Suppose the knowledge-base articles don’t solve the problem.</p><p>The user wants to raise a support ticket.</p><p>So we add:</p><pre>createSupportTicket()</pre><p>Unlike our previous tools, this one changes application state.</p><p>Let’s start with the service:</p><pre>export function createTicket({<br>  subject,<br>  description,<br>  category,<br>}) {<br>  const ticket = {<br>    id: `TKT-${Date.now()}`,<br>    subject,<br>    description,<br>    category,<br>    status: &#39;OPEN&#39;,<br>    createdAt: new Date().toISOString(),<br>  };<br><br>  tickets.push(ticket);<br><br>  return ticket;<br>}</pre><p>And expose it:</p><pre>const createSupportTicketTool = {<br>  name: &#39;createSupportTicket&#39;,<br><br>  description:<br>    &#39;Create a new support ticket when the user has an unresolved issue.&#39;,<br><br>  inputSchema: {<br>    type: &#39;object&#39;,<br><br>    properties: {<br>      subject: {<br>        type: &#39;string&#39;,<br>        description:<br>          &#39;A short summary of the problem.&#39;,<br>      },<br><br>      description: {<br>        type: &#39;string&#39;,<br>        description:<br>          &#39;A detailed explanation of the problem.&#39;,<br>      },<br><br>      category: {<br>        type: &#39;string&#39;,<br>        enum: [<br>          &#39;payment&#39;,<br>          &#39;account&#39;,<br>          &#39;technical&#39;,<br>          &#39;other&#39;,<br>        ],<br>      },<br>    },<br><br>    required: [<br>      &#39;subject&#39;,<br>      &#39;description&#39;,<br>      &#39;category&#39;,<br>    ],<br>  },<br><br>  annotations: {<br>    readOnlyHint: false,<br>    consequentialHint: true,<br>  },<br><br>  execute: async (input) =&gt; {<br>    const ticket = createTicket(input);<br><br>    return JSON.stringify({<br>      success: true,<br>      ticketId: ticket.id,<br>      status: ticket.status,<br>    });<br>  },<br>};</pre><p>And now we’ve crossed an important boundary.</p><p>Before:</p><pre>Agent → Application → READ</pre><p>Now:</p><pre>Agent → Application → CHANGE SOMETHING</pre><p>That deserves a different level of attention.</p><h3>8. A schema doesn’t mean the input is safe</h3><p>It’s tempting to look at the inputSchema and think:</p><blockquote><em>Great. We’ve defined what the agent is allowed to send.</em></blockquote><p>Not quite.</p><p>The schema helps describe the tool contract.</p><p>But the application still owns validation.</p><p>An agent could produce:</p><pre>{<br>  subject: &#39;&#39;,<br>  description: &#39;help&#39;,<br>  category: &#39;something-random&#39;<br>}</pre><p>Or a compromised caller could bypass the agent entirely and invoke the underlying operation directly.</p><p>So the service boundary still needs validation.</p><p>For example, using Zod:</p><pre>import { z } from &#39;zod&#39;;<br><br>const TicketSchema = z.object({<br>  subject: z<br>    .string()<br>    .trim()<br>    .min(5)<br>    .max(100),<br><br>  description: z<br>    .string()<br>    .trim()<br>    .min(10)<br>    .max(2000),<br><br>  category: z.enum([<br>    &#39;payment&#39;,<br>    &#39;account&#39;,<br>    &#39;technical&#39;,<br>    &#39;other&#39;,<br>  ]),<br>});</pre><p>Then our tool becomes:</p><pre>execute: async (input) =&gt; {<br>  const validation =<br>    TicketSchema.safeParse(input);<br><br>  if (!validation.success) {<br>    return JSON.stringify({<br>      success: false,<br><br>      error: {<br>        code: &#39;INVALID_INPUT&#39;,<br><br>        fields:<br>          validation.error.issues.map(<br>            (issue) =&gt; ({<br>              path: issue.path.join(&#39;.&#39;),<br>              message: issue.message,<br>            })<br>          ),<br>      },<br>    });<br>  }<br><br>  const ticket =<br>    createTicket(validation.data);<br><br>  return JSON.stringify({<br>    success: true,<br>    ticketId: ticket.id,<br>    status: ticket.status,<br>  });<br>}</pre><p>This gives us an important separation:</p><pre>WebMCP input schema<br>        │<br>        │ Helps agent understand<br>        │ what to provide<br>        ▼<br>      Agent<br>        │<br>        ▼<br>Application validation<br>        │<br>        │ Decides whether input<br>        │ is actually acceptable<br>        ▼<br> Business operation</pre><p>I think this distinction matters beyond WebMCP.</p><p><strong>Never make the agent part of your trust boundary.</strong></p><p>The application should still behave correctly even when the caller provides bad input.</p><h3>9. Registering four tools without destroying App.jsx</h3><p>Our first WebMCP POC could comfortably register one tool inside a component.</p><p>Four tools already start making that ugly.</p><p>And a real application could have many more.</p><p>I wouldn’t want this:</p><pre>function App() {<br>  useEffect(() =&gt; {<br>    // 300 lines of WebMCP tool definitions...<br>  }, []);<br><br>  return (...);<br>}</pre><p>So let’s give WebMCP its own boundary.</p><p>A simple structure could be:</p><pre>src/<br>│<br>├── components/<br>│<br>├── services/<br>│   ├── knowledgeBaseService.js<br>│   └── ticketService.js<br>│<br>├── webmcp/<br>│   ├── searchKnowledgeBase.tool.js<br>│   ├── getArticle.tool.js<br>│   ├── getTicketStatus.tool.js<br>│   ├── createSupportTicket.tool.js<br>│   ├── tools.js<br>│   └── registerTools.js<br>│<br>└── App.jsx</pre><p>tools.js becomes boring:</p><pre>import { searchKnowledgeBaseTool }<br>  from &#39;./searchKnowledgeBase.tool&#39;;<br><br>import { getArticleTool }<br>  from &#39;./getArticle.tool&#39;;<br><br>import { getTicketStatusTool }<br>  from &#39;./getTicketStatus.tool&#39;;<br><br>import { createSupportTicketTool }<br>  from &#39;./createSupportTicket.tool&#39;;<br><br>export const tools = [<br>  searchKnowledgeBaseTool,<br>  getArticleTool,<br>  getTicketStatusTool,<br>  createSupportTicketTool,<br>];</pre><p>And registration becomes reusable:</p><pre>export async function registerTools(<br>  modelContext,<br>  tools,<br>  signal<br>) {<br>  await Promise.all(<br>    tools.map((tool) =&gt;<br>      modelContext.registerTool(<br>        tool,<br>        { signal }<br>      )<br>    )<br>  );<br>}</pre><p>Then the React integration is small:</p><pre>useEffect(() =&gt; {<br>  const modelContext =<br>    document.modelContext;<br><br>  if (!modelContext) {<br>    return;<br>  }<br><br>  const controller =<br>    new AbortController();<br><br>  registerTools(<br>    modelContext,<br>    tools,<br>    controller.signal<br>  ).catch((error) =&gt; {<br>    if (!controller.signal.aborted) {<br>      console.error(<br>        &#39;Unable to register WebMCP tools&#39;,<br>        error<br>      );<br>    }<br>  });<br><br>  return () =&gt; {<br>    controller.abort();<br>  };<br>}, []);</pre><p>I prefer this structure because the React application doesn’t become coupled to all the details of the agent interface.</p><p>We have:</p><pre>React UI<br>   │<br>   └──────────┐<br>              ▼<br>        Service Layer<br>              ▲<br>   ┌──────────┘<br>   │<br>WebMCP Tools</pre><p>Both interfaces reuse the same application capabilities.</p><h3>10. Tools shouldn’t always be available</h3><p>This was another interesting question.</p><p>Suppose anyone can search public help articles.</p><p>But only authenticated users should be able to see their tickets or create one.</p><p>Then exposing the same tools all the time doesn’t really make sense.</p><p>For an anonymous user:</p><pre>searchKnowledgeBase     ✓<br>getArticle              ✓</pre><pre>getTicketStatus         ✗<br>createSupportTicket     ✗</pre><p>After login:</p><pre>searchKnowledgeBase     ✓<br>getArticle              ✓<br>getTicketStatus         ✓<br>createSupportTicket     ✓</pre><p>This means the tool surface can reflect application state.</p><p>Conceptually:</p><pre>User Session<br>                  │<br>                  ▼<br>          Authentication<br>                  │<br>                  ▼<br>          Authorization<br>                  │<br>                  ▼<br>       Available Capabilities<br>                  │<br>                  ▼<br>        Registered WebMCP Tools</pre><p>That starts to feel much closer to a real application.</p><p>A tool shouldn’t exist merely because somebody wrote the JavaScript function.</p><p>It should be exposed because <strong>the current user is allowed to perform that capability in the current context</strong>.</p><p>And even then, the backend must still enforce authorization.</p><p>Hiding or unregistering a WebMCP tool is useful UX and capability management.</p><p>It is not an authorization mechanism.</p><h3>11. Now we finally have an interesting agent workflow</h3><p>Let’s return to the original user problem.</p><p>Suppose the user says:</p><blockquote><strong><em>“My card payment keeps failing. Check whether there’s a known solution. If there isn’t, help me raise a support ticket.”</em></strong></blockquote><p>We have four tools available:</p><pre>searchKnowledgeBase()<br>getArticle()<br>getTicketStatus()<br>createSupportTicket()</pre><p>A capable agent could reason roughly like this:</p><pre>User reports payment problem<br>             │<br>             ▼<br> searchKnowledgeBase({<br>   query: &quot;card payment failing&quot;<br> })<br>             │<br>             ▼<br>       Search results<br>             │<br>      ┌──────┴──────┐<br>      │             │<br>Relevant          Nothing<br>article           useful<br>      │             │<br>      ▼             ▼<br>getArticle()   Prepare ticket<br>      │             │<br>      ▼             ▼<br>Explain fix    Ask for / confirm<br>to user        required details<br>                    │<br>                    ▼<br>             User confirms<br>                    │<br>                    ▼<br>          createSupportTicket()<br>                    │<br>                    ▼<br>              Ticket ID</pre><p>Notice what we <strong>didn’t</strong> build.</p><p>We didn’t create:</p><pre>solveCustomerProblem()</pre><p>And we didn’t hardcode this entire workflow into React.</p><p>We exposed a small set of capabilities.</p><p>The agent can decide which ones are useful for the current request.</p><p>That, to me, is where WebMCP becomes much more interesting than browser automation.</p><h3>12. But WebMCP isn’t doing the reasoning</h3><p>This distinction is easy to blur.</p><p>WebMCP isn’t looking at:</p><blockquote><em>“My payment keeps failing…”</em></blockquote><p>and independently deciding to search the knowledge base.</p><p>The <strong>agent</strong> is doing that reasoning.</p><p>WebMCP provides the structured interface between the agent and the web application.</p><p>Think of the responsibilities like this:</p><pre>USER<br>&quot;What can I do about this payment problem?&quot;<br><br>                 │<br>                 ▼<br><br>AI AGENT<br>Understands intent<br>Plans next action<br>Chooses a tool<br>Creates arguments<br>Interprets result<br><br>                 │<br>                 ▼<br><br>WEBMCP<br>Exposes available tools<br>Provides schemas<br>Routes tool execution<br><br>                 │<br>                 ▼<br><br>APPLICATION<br>Validates input<br>Enforces authorization<br>Executes business logic<br>Returns result<br><br>                 │<br>                 ▼<br><br>BACKEND<br>Owns data<br>Enforces security<br>Performs operation</pre><p>Keeping those responsibilities separate makes the architecture much easier to reason about.</p><h3>13. What happens when something fails?</h3><p>Happy-path demos are easy.</p><p>Real applications spend a surprising amount of time <em>not</em> on the happy path.</p><p>What if:</p><pre>searchKnowledgeBase()</pre><p>returns nothing?</p><p>What if:</p><pre>getTicketStatus()</pre><p>receives an invalid ticket ID?</p><p>What if the support service is temporarily unavailable?</p><p>What if authentication expires halfway through the interaction?</p><p>Tool results should make those situations understandable.</p><p>I prefer returning structured errors rather than throwing arbitrary strings.</p><p>For example:</p><pre>return JSON.stringify({<br>  success: false,<br><br>  error: {<br>    code: &#39;TICKET_NOT_FOUND&#39;,<br>    message:<br>      &#39;No support ticket was found with that ID.&#39;,<br>    retryable: false,<br>  },<br>});</pre><p>Compare that with:</p><pre>throw new Error(&#39;Something went wrong&#39;);</pre><p>The first response gives the consumer something it can reason about.</p><p>Maybe the agent can ask:</p><blockquote><em>“I couldn’t find ticket TKT-9999. Can you check the ticket number?”</em></blockquote><p>That’s much better than simply telling the user that an error occurred.</p><p>Again, this starts feeling like API design.</p><p>Because in many ways, that’s exactly what we’re doing.</p><p>We’re designing an <strong>agent-facing API at the web application boundary</strong>.</p><h3>14. Read tools and write tools shouldn’t feel the same</h3><p>There’s another distinction I’d make explicit.</p><p>These tools:</p><pre>searchKnowledgeBase()<br>getArticle()<br>getTicketStatus()</pre><p>retrieve information.</p><p>This tool:</p><pre>createSupportTicket()</pre><p>creates something.</p><p>Now imagine adding:</p><pre>closeSupportTicket()<br>deleteAccount()<br>cancelSubscription()<br>makePayment()</pre><p>The risk increases quickly.</p><p>I wouldn’t want an agent to infer:</p><blockquote><em>“The user seems unhappy with the subscription.”</em></blockquote><p>and immediately call:</p><pre>cancelSubscription()</pre><p>without an appropriate confirmation step.</p><p>So when designing agent-facing capabilities, I’d classify them mentally as something like:</p><pre>LOW CONSEQUENCE<br>───────────────<br>Search<br>Read<br>Lookup<br>Preview<br><br><br>STATE CHANGING<br>──────────────<br>Create<br>Update<br>Submit<br><br><br>HIGH CONSEQUENCE<br>────────────────<br>Delete<br>Purchase<br>Cancel<br>Transfer<br>Confirm payment</pre><p>The more consequential the action, the more important authentication, authorization, validation, confirmation and auditability become.</p><p>That’s not a WebMCP-specific principle.</p><p>But WebMCP makes the question impossible to ignore because we’re explicitly giving an agent callable capabilities.</p><h3>15. What I would log</h3><p>Once agents can execute application tools, observability becomes interesting too.</p><p>For each invocation, I’d want enough information to answer:</p><pre>Which tool was called?<br>When?<br>Did it succeed?<br>How long did it take?<br>What category of error occurred?<br>Was it read-only or state-changing?</pre><p>Not:</p><pre>Dump every prompt and every piece<br>of potentially sensitive user data.</pre><p>Something like:</p><pre>{<br>  tool: &#39;searchKnowledgeBase&#39;,<br>  status: &#39;success&#39;,<br>  durationMs: 84,<br>  timestamp: &#39;...&#39;,<br>}</pre><p>could be useful operationally.</p><p>For a state-changing operation:</p><pre>{<br>  tool: &#39;createSupportTicket&#39;,<br>  status: &#39;success&#39;,<br>  resourceId: &#39;TKT-1087&#39;,<br>  timestamp: &#39;...&#39;,<br>}</pre><p>depending, of course, on the application’s privacy and logging requirements.</p><p>If agent interactions become a real production interface, they need the same operational thinking as any other production interface.</p><h3>16. Five things changed for me after building multiple tools</h3><p>My first WebMCP experiment was mostly about understanding the API.</p><p>This second experiment changed how I thought about the architecture.</p><h3>1. Tool design is API design</h3><p>With one tool, naming doesn’t seem terribly important.</p><p>With twenty tools, it absolutely is.</p><p>These are bad:</p><pre>doSearch()<br>handleUser()<br>processData()<br>executeAction()</pre><p>The agent has very little semantic information.</p><p>These are clearer:</p><pre>searchKnowledgeBase()<br>getArticle()<br>getTicketStatus()<br>createSupportTicket()</pre><p>The capability should be obvious from its name and description.</p><h3>2. Smaller tools are easier to compose</h3><p>My instinct is now to expose capabilities rather than entire workflows.</p><p>Instead of:</p><pre>resolveSupportProblem()</pre><p>provide the useful building blocks.</p><p>The agent can compose them when appropriate.</p><h3>3. Business logic should stay out of the tool definition</h3><p>I want this:</p><pre>WebMCP Tool<br>     │<br>     ▼<br>Validation<br>     │<br>     ▼<br>Application Service<br>     │<br>     ▼<br>Backend</pre><p>not:</p><pre>WebMCP Tool<br>     │<br>     ▼<br>Authentication logic<br>Business rules<br>Database mapping<br>UI state<br>Error transformation<br>Analytics<br>500 more lines...</pre><p>A WebMCP tool should ideally be a thin adapter around capabilities the application already owns.</p><h3>4. Tool availability is part of application state</h3><p>The agent shouldn’t necessarily see every capability the application has.</p><p>The useful question is:</p><blockquote><strong><em>What can this user legitimately do, right now, in this context?</em></strong></blockquote><p>That should shape the available tool surface.</p><h3>5. Security becomes part of tool design from day one</h3><p>When the only tool is:</p><pre>searchFlights()</pre><p>it’s easy to focus entirely on the cool part.</p><p>Once you add:</p><pre>createTicket()<br>updateProfile()<br>cancelOrder()<br>makePayment()</pre><p>the conversation changes.</p><p>And that’s healthy.</p><p>Agent-ready application design can’t be separated from authorization, validation, confirmation and observability.</p><h3>17. The architecture I ended up with</h3><p>After experimenting with the support application, this is the mental model I found most useful:</p><pre>USER<br>                           │<br>                ┌──────────┴──────────┐<br>                │                     │<br>             HUMAN                 AI AGENT<br>                │                     │<br>                ▼                     ▼<br>           React UI                WebMCP<br>                │                     │<br>                └──────────┬──────────┘<br>                           │<br>                           ▼<br>                    VALIDATION<br>                           │<br>                           ▼<br>                  APPLICATION SERVICES<br>                           │<br>                           ▼<br>                     BACKEND APIs<br>                           │<br>                           ▼<br>                         DATA</pre><p>Two interfaces.</p><p>One application.</p><p>One set of business capabilities.</p><p>That feels much healthier to me than building a separate “AI version” of the application.</p><h3>Where this leaves the Agentic Web</h3><p>In Part 1, my question was:</p><blockquote><strong><em>Can a React application expose functionality directly to an AI agent?</em></strong></blockquote><p>The small flight-search POC answered that.</p><p>Yes.</p><p>But after going beyond one tool, I think the more interesting question is:</p><blockquote><strong><em>How should we design web applications when AI agents become another legitimate consumer of application capabilities?</em></strong></blockquote><p>That’s not really a WebMCP API question.</p><p>It’s an architecture question.</p><p>We need to think about:</p><pre>Tool boundaries<br>Tool naming<br>Schemas<br>Validation<br>Authentication<br>Authorization<br>Application state<br>Error contracts<br>Confirmation<br>Observability<br>Lifecycle</pre><p>And interestingly, most of those aren’t new concepts.</p><p>We’ve dealt with them for years while designing APIs and distributed systems.</p><p>What’s new is <strong>where the consumer sits</strong>.</p><p>Instead of another backend service consuming the contract, the consumer may be an AI agent operating in the user’s browser.</p><h3>Final thoughts</h3><p>My first WebMCP POC made me think:</p><blockquote><em>“This is a cleaner way for an agent to interact with a web application.”</em></blockquote><p>The second one made me think about something broader.</p><p>Maybe making a web application “agent-ready” isn’t about adding an AI chatbot or sprinkling a few tools into the frontend.</p><p>Maybe it’s about treating agents as another interface to the capabilities our applications already provide.</p><p>Humans still need great interfaces.</p><p>We still need buttons, forms, navigation, accessibility, responsive layouts and good UX.</p><p>None of that goes away.</p><p>But alongside that human interface, applications may increasingly expose a second interface:</p><pre>Application<br>                        │<br>             ┌──────────┴──────────┐<br>             │                     │<br>      Human Interface       Agent Interface<br>             │                     │<br>        UI / UX                  Tools<br>             │                     │<br>             └──────────┬──────────┘<br>                        │<br>                  Business Logic</pre><p>In the first article, I exposed one tool.</p><p>In this one, I exposed several and let them form a workflow.</p><p>And that leaves me with one more question that I think is worth exploring:</p><blockquote><strong><em>What happens when these tools need to work with authentication, real APIs, application state and an actual AI agent rather than a DevTools experiment?</em></strong></blockquote><p>That’s probably where the next chapter of this experiment begins.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca085b94b9ab" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Agentic Web: Making React Applications AI-Agent Ready with WebMCP]]></title>
            <link>https://medium.com/@rahulkuma/the-agentic-web-making-react-applications-ai-agent-ready-with-webmcp-0aaa1a66437a?source=rss-c92746bd5961------2</link>
            <guid isPermaLink="false">https://medium.com/p/0aaa1a66437a</guid>
            <dc:creator><![CDATA[Rahul kumar]]></dc:creator>
            <pubDate>Sat, 10 Oct 2026 09:16:56 GMT</pubDate>
            <atom:updated>2026-10-10T09:16:56.119Z</atom:updated>
            <content:encoded><![CDATA[<p>For most of my frontend career, the assumption has been pretty simple: <strong>we build web applications for people.</strong></p><p>A user opens a page, fills in a form, clicks a button, and gets a result. As frontend developers, we spend a lot of time making that journey better — responsive layouts, accessibility, performance, error handling, and so on.</p><p>Let’s take a simple example.</p><p>Suppose I have a React application for searching flights. A user can select Delhi as the origin, Mumbai as the destination, and click <strong>Search Flights</strong>.</p><p>For us, that’s completely normal:</p><p><strong>User<br> ↓<br>Form<br> ↓<br>Search button<br> ↓<br>Application logic<br> ↓<br>Results</strong></p><p>Now imagine an AI agent trying to do the same thing.</p><p>It has to understand the page, identify the right input fields, enter the values, find the Search button, click it, wait for the page to update, and then understand the results.</p><p>Modern browser agents are getting increasingly good at this. But while experimenting with this idea, I started wondering:</p><p><strong>Why should an agent have to figure out how to click through a UI when the application already knows exactly what “search for flights” means?</strong></p><p>That’s what led me to <strong>WebMCP</strong>.</p><h3>So, what exactly is WebMCP?</h3><p>The easiest way I found to understand WebMCP is to stop thinking about AI for a moment.</p><p>Imagine our application already has a function like this:</p><pre>searchFlights({<br>  origin: &#39;DEL&#39;,<br>  destination: &#39;BOM&#39;,<br>});</pre><p>Our React UI eventually triggers that functionality when someone fills in the form and clicks Search.</p><p>But an AI agent doesn’t necessarily know that this capability exists. All it sees is the interface presented by the page.</p><p>With WebMCP, the application can expose that capability as a structured <strong>tool</strong>.</p><p>In simple terms, the application can tell an agent:</p><p><strong>“I have a tool called </strong><strong>searchFlights. Give me an origin and destination, and I can search for available flights.”</strong></p><p>That changes the interaction quite a bit.</p><p>Instead of:</p><pre>AI Agent<br>   ↓<br>Understand the page<br>   ↓<br>Find origin input<br>   ↓<br>Find destination input<br>   ↓<br>Fill both fields<br>   ↓<br>Find Search button<br>   ↓<br>Click<br>   ↓<br>Interpret results</pre><p>we can potentially have:</p><pre>AI Agent<br>   ↓<br>Discover available tools<br>   ↓<br>searchFlights({<br>  origin: &#39;DEL&#39;,<br>  destination: &#39;BOM&#39;<br>})<br>   ↓<br>Application<br>   ↓<br>Results</pre><p>The UI hasn’t disappeared. A human can still use exactly the same application.</p><p>We’ve simply added another way of interacting with it.</p><p>And that’s the part of WebMCP I find most interesting.</p><p><strong>Wait, isn’t this what MCP already does?</strong></p><p>This was one of my first questions.</p><p>I’d already heard plenty about MCP, so when I came across WebMCP my initial reaction was:</p><p><strong>Do we really need another MCP?</strong></p><p>The distinction became clearer once I stopped thinking about them as competing technologies.</p><p>With MCP, you might have something like:</p><pre>AI Assistant<br>     ↓<br>MCP Server<br>     ↓<br>Backend service / database / external system</pre><p>WebMCP is much closer to the web application the user currently has open:</p><pre>Browser Agent<br>     ↓<br>WebMCP<br>     ↓<br>Current Web Page<br>     ↓<br>Application functionality</pre><p>So I wouldn’t think of WebMCP as “MCP, but in JavaScript.”</p><p>The interesting part is that the <strong>web page itself can expose capabilities related to its current state and functionality</strong>.</p><p>MCP and WebMCP can therefore solve different parts of an agentic application rather than one replacing the other.</p><h3>I wanted to see this working</h3><p>Reading about WebMCP was useful, but I didn’t really understand it until I built something small.</p><p>I created a basic React application with two fields:</p><pre>Origin:      DEL<br>Destination: BOM<br><br>[ Search Flights ]</pre><p>Nothing sophisticated.</p><p>Behind it I used some mock data:</p><pre>const flights = [<br>  {<br>    flightNumber: &#39;FL101&#39;,<br>    origin: &#39;DEL&#39;,<br>    destination: &#39;BOM&#39;,<br>    departure: &#39;08:30&#39;,<br>  },<br>  {<br>    flightNumber: &#39;FL205&#39;,<br>    origin: &#39;DEL&#39;,<br>    destination: &#39;BOM&#39;,<br>    departure: &#39;11:15&#39;,<br>  },<br>];</pre><p>And a normal JavaScript function:</p><pre>function searchFlights({ origin, destination }) {<br>  return flights.filter(<br>    (flight) =&gt;<br>      flight.origin === origin.toUpperCase() &amp;&amp;<br>      flight.destination === destination.toUpperCase()<br>  );<br>}</pre><p>There’s nothing WebMCP-specific here.</p><p>And I think that’s important.</p><p>I don’t want my application logic to care whether the request came from a React button or an AI agent.</p><p>The interesting part comes next.</p><h3>Turning that function into a tool</h3><p>To make the operation discoverable, I registered it with WebMCP.</p><p>Conceptually, the registration looks like this:</p><pre>const searchFlightsTool = {<br>  name: &#39;searchFlights&#39;,<br><br>  description:<br>    &#39;Search available flights using origin and destination airport codes.&#39;,<br><br>  inputSchema: {<br>    type: &#39;object&#39;,<br>    properties: {<br>      origin: {<br>        type: &#39;string&#39;,<br>        description: &#39;Origin airport code, such as DEL&#39;,<br>      },<br>      destination: {<br>        type: &#39;string&#39;,<br>        description: &#39;Destination airport code, such as BOM&#39;,<br>      },<br>    },<br>    required: [&#39;origin&#39;, &#39;destination&#39;],<br>  },<br><br>  execute: async ({ origin, destination }) =&gt; {<br>    const results = searchFlights({<br>      origin,<br>      destination,<br>    });<br><br>    return JSON.stringify({<br>      count: results.length,<br>      flights: results,<br>    });<br>  },<br>};</pre><p>There were three things here that helped WebMCP click for me.</p><p><strong>The name tells the agent what capability exists.</strong></p><p><strong>The description gives the agent some context about when it should use it.</strong></p><p>And <strong>the input schema provides a contract</strong> for what the tool needs.</p><p>The agent doesn’t need to know anything about my React components or how searchFlights() is implemented internally.</p><p>It only needs to understand the contract.</p><h3>React added one small complication</h3><p>My first instinct was basically:</p><blockquote><em>Register the tool when the component loads. Done.</em></blockquote><p>React reminded me that things are rarely quite that simple.</p><p>During development, components can mount and unmount, and React’s development behavior can expose lifecycle problems pretty quickly. I initially ran into a duplicate-tool registration error.</p><p>The fix was to tie the WebMCP registration to the React lifecycle using an AbortController:</p><pre>useEffect(() =&gt; {<br>  if (!document.modelContext) {<br>    return;<br>  }<br><br>  const controller = new AbortController();<br><br>  document.modelContext.registerTool(<br>    searchFlightsTool,<br>    {<br>      signal: controller.signal,<br>    }<br>  );<br><br>  return () =&gt; {<br>    controller.abort();<br>  };<br>}, []);</pre><p>That small issue actually taught me something useful.</p><p><strong>Agent-facing capabilities have a lifecycle too.</strong></p><p>If a tool is only valid while a particular part of the application is active, we shouldn’t necessarily expose it forever.</p><p>For a large SPA, that becomes quite interesting. The tools available on a search page might be completely different from the tools available on a checkout page.</p><h3>Seeing the tool for the first time</h3><p>Once the registration was working, I could ask the browser what tools the page exposed:</p><pre>const tools =<br>  await document.modelContext.getTools();<br><br>console.log(tools);</pre><p>And there it was:</p><pre>searchFlights</pre><p>I could then execute it with:</p><pre>const tool = tools.find(<br>  (item) =&gt; item.name === &#39;searchFlights&#39;<br>);<br><br>await document.modelContext.executeTool(<br>  tool,<br>  {<br>    origin: &#39;DEL&#39;,<br>    destination: &#39;BOM&#39;,<br>  }<br>);</pre><p>and get the matching flights back.</p><p>It’s a tiny demo, but this was the point where the concept became much clearer to me.</p><p>My React application now effectively had <strong>two interfaces</strong>:</p><pre>                 Application Logic<br>                       ↑<br>             ┌─────────┴─────────┐<br>             │                   │<br>         React UI             WebMCP<br>             ↑                   ↑<br>           Human              AI Agent</pre><p>The important part is that both paths can eventually reuse the same business logic.</p><h3>This doesn’t automatically make the application “agentic”</h3><p>There’s an important distinction here.</p><p>Registering a WebMCP tool doesn’t suddenly mean an AI agent is running inside your application.</p><p>In my POC, I manually discovered and executed the tool through the browser tooling.</p><p>A real agent adds another layer:</p><pre>&quot;Find flights from Delhi to Mumbai&quot;<br>                 ↓<br>              Agent<br>                 ↓<br>       Understand the request<br>                 ↓<br>       Discover available tools<br>                 ↓<br>       Choose searchFlights<br>                 ↓<br>       Generate arguments<br>                 ↓<br>          Execute the tool<br>                 ↓<br>        Interpret the result</pre><p>I think this distinction is important because it’s easy to see a tool executing and call the whole thing “agentic.”</p><p>WebMCP provides the <strong>capability interface</strong>. The agent is responsible for reasoning about when and how to use that capability.</p><h3>Where this gets more interesting</h3><p>Flight search is deliberately simple.</p><p>Now imagine an application exposing:</p><pre>searchProducts()<br>getOrderStatus()<br>downloadInvoice()<br>createSupportTicket()</pre><p>Or perhaps:</p><pre>getTasks()<br>createTask()<br>updateTaskStatus()</pre><p>Suddenly the web application isn’t only presenting pixels and DOM elements to an agent.</p><p>It’s describing <strong>what it can actually do</strong>.</p><p>But I don’t think the answer is to expose every function in the application.</p><p>That would probably create a different mess.</p><p>The better question is:</p><blockquote><strong><em>Which user journeys would genuinely benefit from being exposed as clear, well-designed tools?</em></strong></blockquote><p>That’s much closer to API design than UI development.</p><p>Tool names matter.</p><p>Descriptions matter.</p><p>Input schemas matter.</p><p>Error responses matter.</p><p>And the boundaries between tools matter.</p><p>Frontend developers may find themselves thinking about all of these things much more often.</p><h3>Then comes the uncomfortable part: security</h3><p>A tool like:</p><pre>searchFlights()</pre><p>is fairly harmless.</p><p>A tool like:</p><pre>confirmBooking()</pre><p>isn’t.</p><p>One retrieves information. The other might create a financial transaction.</p><p>That means making a website agent-accessible cannot simply mean:</p><blockquote><em>“Expose all our functions as tools.”</em></blockquote><p>Authentication and authorization still belong to the application. Inputs still need validation. Sensitive actions still need appropriate confirmation.</p><p>WebMCP can provide hints about whether a tool is read-only or consequential, but those hints aren’t security boundaries.</p><p>I would start experimenting with <strong>read-only tools first</strong>.</p><p>Search, lookup, status retrieval and similar operations provide plenty of room to learn without immediately giving an agent the ability to perform irreversible actions.</p><p>There is also the broader issue of untrusted content and prompt injection. If an agent consumes information from a page or tool result, we can’t assume every piece of text it encounters should be treated as an instruction.</p><p>The agentic web doesn’t remove existing web-security concerns. It adds a few new ones.</p><h3>Is WebMCP production-ready?</h3><p>I wouldn’t build a critical production workflow around it today without carefully considering browser support and the fact that the specification is still evolving.</p><p>That’s also why I think <strong>now is a good time to experiment with it</strong>.</p><p>A small POC teaches you quite a lot:</p><ul><li>how tools are designed,</li><li>how schemas influence agent interaction,</li><li>how tool lifecycle fits into an SPA,</li><li>where application state belongs,</li><li>what should and shouldn’t be exposed,</li><li>and where security boundaries need to exist.</li></ul><p>You can learn all of that without redesigning your application.</p><h3>The bigger idea</h3><p>The part I’m taking away from this experiment isn’t actually the API.</p><p>APIs change.</p><p>Browser implementations change.</p><p>Standards evolve.</p><p>The bigger idea is that web applications may eventually have <strong>two equally intentional interfaces</strong>:</p><pre>                   Web Application<br>                         │<br>              ┌──────────┴──────────┐<br>              │                     │<br>       Human Interface       Agent Interface<br>              │                     │<br>       Buttons / Forms          Tools<br>              │                     │<br>              └──────────┬──────────┘<br>                         │<br>                  Business Logic</pre><p>We’ve spent decades making the left-hand side better.</p><p>Maybe we’re now at the beginning of figuring out what the right-hand side should look like.</p><h3>Final thoughts</h3><p>After building the small POC, I don’t see WebMCP as a replacement for React, APIs, MCP, or traditional browser interaction.</p><p>I see it as another interface into a web application.</p><p>For a human, we expose buttons, forms, navigation and visual feedback.</p><p>For an agent, we may increasingly expose structured capabilities with clear names, descriptions and input contracts.</p><p>Whether WebMCP itself becomes the long-term standard is something we’ll have to watch.</p><p>But the question it raises is already useful:</p><blockquote><strong><em>If an AI agent needed to use my web application tomorrow, would it have to figure out my UI — or could my application simply tell it what it knows how to do?</em></strong></blockquote><p>For frontend developers, I think that’s a question worth experimenting with.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0aaa1a66437a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Custom Hooks in React: Reusable Logic Made Simple]]></title>
            <link>https://medium.com/@rahulkuma/custom-hooks-in-react-reusable-logic-made-simple-f1223902f7a3?source=rss-c92746bd5961------2</link>
            <guid isPermaLink="false">https://medium.com/p/f1223902f7a3</guid>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[hooks]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Rahul kumar]]></dc:creator>
            <pubDate>Tue, 29 Jul 2025 10:43:33 GMT</pubDate>
            <atom:updated>2025-07-29T10:43:33.876Z</atom:updated>
            <content:encoded><![CDATA[<p>React is all about <strong>components</strong> and <strong>composition</strong>, but as applications grow, so does the need to <strong>reuse stateful logic</strong> across multiple components. That’s where <strong>custom hooks</strong> come into play.</p><p>In this article, we’ll break down what custom hooks are, why they matter, and how to build and use them effectively. Whether you’re a React beginner or an experienced developer, this guide will help you write cleaner and more maintainable code using custom hooks.</p><h3>Why Custom Hooks?</h3><p>Before React Hooks were introduced in version 16.8, logic reuse was largely handled using <strong>Higher-Order Components (HOCs)</strong> or <strong>Render Props</strong>. While they worked, both came with their own complexity and boilerplate.</p><p>Hooks simplified state and lifecycle management inside functional components. But built-in hooks like useState, useEffect, and useContext are just the beginning.</p><p>As you work on larger projects, you’ll often find yourself repeating logic — like:</p><ul><li>Fetching data from APIs</li><li>Handling form input and validation</li><li>Managing localStorage or sessionStorage</li><li>Adding event listeners (scroll, resize, etc.)</li></ul><p>To avoid duplicating this logic, <strong>you can extract it into a custom hook</strong>.</p><h3>What Is a Custom Hook?</h3><p>A <strong>custom hook</strong> is a <strong>JavaScript function</strong> whose name starts with use and may call other hooks inside it.</p><pre>function useCustomHook() {<br>  const [value, setValue] = useState(null);<br>  useEffect(() =&gt; {<br>    // do something<br>  }, []);<br>  return [value, setValue];<br>}</pre><h3>Rules of Hooks still apply:</h3><p>Call hooks only at the top level.</p><p>Call hooks only from React functions (components or custom hooks).</p><h3>Building Your First Custom Hook</h3><p>Let’s create a custom hook called useWindowWidth that tracks the browser window&#39;s width and updates it when the window is resized.</p><h3>Problem:</h3><p>We need to monitor window.innerWidth across different components (like responsive layouts).</p><h3>Solution: Custom Hook</h3><pre>function useWindowWidth() {<br>  const [width, setWidth] = useState(window.innerWidth);</pre><pre>  useEffect(() =&gt; {<br>    const handleResize = () =&gt; setWidth(window.innerWidth);</pre><pre>    window.addEventListener(&#39;resize&#39;, handleResize);</pre><pre>    return () =&gt; window.removeEventListener(&#39;resize&#39;, handleResize);<br>  }, []);</pre><pre>  return width;<br>}</pre><h3>Usage in Component</h3><pre>function ResponsiveComponent() {<br>  const width = useWindowWidth();  <br>return (<br>    &lt;div&gt;<br>      &lt;p&gt;Current window width: {width}px&lt;/p&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><h3>Another Common Use Case: Data Fetching Hook</h3><p>Let’s build a useFetch hook to simplify API data fetching.</p><h3>Code:</h3><pre>function useFetch(url) {<br>  const [data, setData] = useState(null);<br>  const [loading, setLoading] = useState(true);<br>  const [error, setError] = useState(null);</pre><pre>  useEffect(() =&gt; {<br>    let isMounted = true;</pre><pre>    const fetchData = async () =&gt; {<br>      try {<br>        setLoading(true);<br>        const response = await fetch(url);<br>        if (!response.ok) throw new Error(&quot;Fetch failed&quot;);<br>        const result = await response.json();<br>        if (isMounted) setData(result);<br>      } catch (err) {<br>        if (isMounted) setError(err);<br>      } finally {<br>        if (isMounted) setLoading(false);<br>      }<br>    };</pre><pre>    fetchData();</pre><pre>    return () =&gt; {<br>      isMounted = false;<br>    };<br>  }, [url]);</pre><pre>  return { data, loading, error };<br>}</pre><h3>Usage:</h3><pre>function UsersList() {<br>  const { data, loading, error } = useFetch(&#39;https://jsonplaceholder.typicode.com/users&#39;);  <br>if (loading) return &lt;p&gt;Loading...&lt;/p&gt;;<br>  if (error) return &lt;p&gt;Error: {error.message}&lt;/p&gt;;<br>return (<br>    &lt;ul&gt;<br>      {data.map(user =&gt; &lt;li key={user.id}&gt;{user.name}&lt;/li&gt;)}<br>    &lt;/ul&gt;<br>  );<br>}</pre><h3>Custom Hooks with Parameters</h3><p>Custom hooks can accept <strong>parameters</strong>, just like any function.</p><h3>Example: useToggle</h3><pre>function useToggle(initialValue = false) {<br>  const [value, setValue] = useState(initialValue);<br>  const toggle = () =&gt; setValue(prev =&gt; !prev);<br>  return [value, toggle];<br>}</pre><h3>Usage:</h3><pre>function ToggleExample() {<br>  const [isVisible, toggleVisibility] = useToggle();  <br>return (<br>    &lt;div&gt;<br>      &lt;button onClick={toggleVisibility}&gt;<br>        {isVisible ? &#39;Hide&#39; : &#39;Show&#39;}<br>      &lt;/button&gt;<br>      {isVisible &amp;&amp; &lt;p&gt;This text is visible&lt;/p&gt;}<br>    &lt;/div&gt;<br>  );<br>}</pre><h3>Organizing Custom Hooks</h3><p>Here are some tips for managing custom hooks in real-world projects:</p><ol><li><strong>Naming Convention</strong>: Always prefix with use. Example: useLocalStorage, useDebounce, useDarkMode.</li><li><strong>Folder Structure</strong>:</li></ol><ul><li>bash</li><li>CopyEdit</li><li>/src /hooks useWindowWidth.js useFetch.js useLocalStorage.js</li></ul><ol><li><strong>Test Your Hooks</strong>: Use tools like React Testing Library + <a href="https://github.com/testing-library/react-hooks">@testing-library/react-hooks</a> for unit tests.</li></ol><h3>Advanced Example: useLocalStorage</h3><p>Let’s create a custom hook that reads/writes to localStorage and keeps React state in sync.</p><pre>function useLocalStorage(key, initialValue) {<br>  const [storedValue, setStoredValue] = useState(() =&gt; {<br>    try {<br>      const item = window.localStorage.getItem(key);<br>      return item ? JSON.parse(item) : initialValue;<br>    } catch (err) {<br>      return initialValue;<br>    }<br>  });</pre><pre>  useEffect(() =&gt; {<br>    try {<br>      window.localStorage.setItem(key, JSON.stringify(storedValue));<br>    } catch (err) {<br>      console.error(err);<br>    }<br>  }, [key, storedValue]);</pre><pre>  return [storedValue, setStoredValue];<br>}</pre><h3>Usage:</h3><pre>function NameSaver() {<br>  const [name, setName] = useLocalStorage(&#39;username&#39;, &#39;&#39;);  <br>return (<br>    &lt;div&gt;<br>      &lt;input<br>        value={name}<br>        onChange={e =&gt; setName(e.target.value)}<br>        placeholder=&quot;Enter name&quot;<br>      /&gt;<br>      &lt;p&gt;Saved name: {name}&lt;/p&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><h3>Benefits of Custom Hooks</h3><ol><li><strong>Reusability</strong>: Avoid repeating the same logic in multiple components.</li><li><strong>Separation of Concerns</strong>: Business logic lives outside UI code.</li><li><strong>Testability</strong>: Easier to test isolated logic.</li><li><strong>Cleaner Components</strong>: Components focus only on rendering, not logic.</li></ol><h3>Common Mistakes to Avoid</h3><p>MistakeWhy It’s BadNot using use prefixReact won’t treat it as a hookUsing hooks inside conditionsBreaks Rules of HooksForgetting cleanup in useEffectCauses memory leaksAssuming hooks re-run on every renderDepends on dependency array</p><h3>When Not to Use Custom Hooks</h3><p>Custom hooks are great, but don’t create them for <strong>everything</strong>. If the logic is only used in <strong>one</strong> place and isn’t very complex, it’s fine to keep it within the component.</p><p>Use a custom hook when:</p><ul><li>Logic is used in <strong>multiple</strong> components.</li><li>It improves <strong>readability</strong> or <strong>testability</strong>.</li><li>It helps isolate <strong>side effects</strong> or async calls.</li></ul><h3>Popular Custom Hooks Libraries</h3><p>If you don’t want to reinvent the wheel, check out:</p><ul><li>usehooks.com</li><li><a href="https://github.com/streamich/react-use">react-use</a></li><li>ahooks</li></ul><p>These provide hooks like:</p><ul><li>usePrevious</li><li>useDebounce</li><li>useThrottle</li><li>useClickAway</li><li>useEventListener</li></ul><h3>Summary</h3><p>Custom hooks are a game-changer in React development. They:</p><ul><li>Encapsulate complex logic</li><li>Promote reuse and cleanliness</li><li>Make components easier to maintain</li></ul><p>Whether it’s syncing to localStorage, fetching data, or managing input forms — custom hooks help you <strong>build scalable and elegant React apps</strong>.</p><h3>Final Thoughts</h3><p>If you find yourself repeating the same logic across components — stop. Wrap it into a custom hook. Your future self (and teammates) will thank you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f1223902f7a3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Native vs Flutter: Which One Should You Choose in 2025?]]></title>
            <link>https://medium.com/@rahulkuma/react-native-vs-flutter-which-one-should-you-choose-in-2025-be6875850af8?source=rss-c92746bd5961------2</link>
            <guid isPermaLink="false">https://medium.com/p/be6875850af8</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[react-and-flutter]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[flutter-vs-react-native]]></category>
            <dc:creator><![CDATA[Rahul kumar]]></dc:creator>
            <pubDate>Wed, 23 Jul 2025 12:01:24 GMT</pubDate>
            <atom:updated>2025-07-23T12:01:24.935Z</atom:updated>
            <content:encoded><![CDATA[<p>In the dynamic world of mobile app development, developers often face the critical decision of selecting the right framework. As we step into 2025, two of the most prominent cross-platform development tools continue to dominate the landscape: <strong>React Native</strong> and <strong>Flutter</strong>. Both have evolved significantly over the years, introducing new features, performance enhancements, and tooling support. But the question remains: <em>Which one should you choose in 2025?</em></p><p>This comprehensive guide will delve into the strengths, weaknesses, and real-world applications of React Native and Flutter to help you make an informed decision.</p><h3>🔧 What is React Native?</h3><p>React Native is a popular open-source mobile application framework created by Facebook (now Meta). It allows developers to build mobile apps using <strong>JavaScript</strong> and <strong>React</strong>. React Native uses native components under the hood and bridges JavaScript code with native APIs, offering near-native performance.</p><h3>Key Features:</h3><ul><li>Written in JavaScript/TypeScript</li><li>Uses React paradigm (component-based architecture)</li><li>Live &amp; hot reloading</li><li>Rich ecosystem and community support</li></ul><h3>🌈 What is Flutter?</h3><p>Flutter is Google’s UI toolkit for building natively compiled applications for mobile, web, and desktop from a single codebase. It uses the <strong>Dart</strong> programming language and offers a rich set of pre-built widgets for crafting beautiful UIs.</p><h3>Key Features:</h3><ul><li>Written in Dart</li><li>High-performance rendering engine (Skia)</li><li>Hot reload</li><li>Beautiful and customizable UI components</li></ul><h3>🆚 Feature-by-Feature Comparison</h3><h3>1. Programming Language</h3><ul><li><strong>React Native</strong>: JavaScript (optionally TypeScript)</li><li><strong>Flutter</strong>: Dart</li></ul><p><strong>Verdict</strong>: JavaScript is more widely known and has a vast talent pool. Dart is less common, but its learning curve is gentle, and it’s gaining popularity thanks to Flutter.</p><h3>2. UI Components and Development Speed</h3><ul><li><strong>React Native</strong> relies on native components. For customized UI, developers often use third-party libraries like react-native-elements or react-native-paper.</li><li><strong>Flutter</strong> offers a rich set of widgets out-of-the-box, giving developers more control and consistency.</li></ul><p><strong>Example</strong>:</p><pre>// React Native Button<br>import { Button } from &#39;react-native&#39;;</pre><pre>&lt;Button title=&quot;Click Me&quot; onPress={() =&gt; alert(&#39;Pressed&#39;)} /&gt;</pre><pre>// Flutter Button<br>ElevatedButton(<br>  onPressed: () =&gt; print(&#39;Pressed&#39;),<br>  child: Text(&#39;Click Me&#39;),<br>)</pre><p><strong>Verdict</strong>: Flutter provides a more unified and customizable UI experience.</p><h3>3. Performance</h3><ul><li><strong>React Native</strong> communicates with native components via a JavaScript bridge, which may cause bottlenecks for complex operations.</li><li><strong>Flutter</strong> compiles directly to native code, offering better performance and faster rendering.</li></ul><p><strong>Verdict</strong>: Flutter has an edge in performance, especially for animations and heavy UI rendering.</p><h3>4. Community and Ecosystem</h3><ul><li><strong>React Native</strong> has a mature ecosystem with a larger community and more third-party packages.</li><li><strong>Flutter</strong> is catching up fast, with strong backing from Google and growing adoption in the developer community.</li></ul><p><strong>Verdict</strong>: React Native has more mature libraries and broader community support as of 2025, but Flutter is not far behind.</p><h3>5. Tooling and IDE Support</h3><ul><li><strong>React Native</strong>: Strong support in VSCode, WebStorm, and debugging tools like Flipper.</li><li><strong>Flutter</strong>: First-class support in Android Studio, IntelliJ, and VSCode, with a dedicated DevTools suite.</li></ul><p><strong>Verdict</strong>: Flutter offers a more integrated development experience, especially for UI debugging.</p><h3>6. Code Reusability and Web/Desktop Support</h3><ul><li><strong>React Native</strong>: Primarily for mobile. Web and desktop support via third-party projects like React Native Web.</li><li><strong>Flutter</strong>: Officially supports mobile, web, and desktop (macOS, Windows, Linux) from a single codebase.</li></ul><p><strong>Verdict</strong>: Flutter shines in multi-platform development.</p><h3>7. Development Experience</h3><p>React Native’s hot reloading and use of JavaScript make it quick to get started, especially for web developers. Flutter’s hot reload is reliable, and the rich UI widgets offer a delightful dev experience.</p><p><strong>Verdict</strong>: Depends on background — React Native is easier for JavaScript developers; Flutter provides better control over UI.</p><h3>🎯 Use Case Scenarios</h3><h3>Choose React Native if:</h3><ul><li>Your team is proficient in JavaScript/React.</li><li>You want to integrate the app with existing native codebases.</li><li>You need access to a wide range of third-party libraries.</li><li>You’re building a lightweight app with standard UI components.</li></ul><p><strong>Example</strong>: Facebook, Instagram, and Discord use React Native for parts of their mobile apps.</p><h3>Choose Flutter if:</h3><ul><li>You’re aiming for a highly customized UI.</li><li>You plan to target mobile, web, and desktop with one codebase.</li><li>You want high performance and smooth animations.</li></ul><p><strong>Example</strong>: Google Ads, eBay Motors, and BMW use Flutter for complex, high-performance apps.</p><h3>🔮 What’s New in 2025?</h3><h3>React Native</h3><ul><li>Fabric architecture is now the default, improving performance and concurrency.</li><li>TurboModules enable faster native module loading.</li><li>Continued support from Meta and open-source contributors.</li></ul><h3>Flutter</h3><ul><li>Flutter 4.0 brings more web performance improvements and smaller bundle sizes.</li><li>Dart 3 offers enhanced null safety and concurrency features.</li><li>Improved integration with Firebase and AI toolkits.</li></ul><h3>🧠 Final Verdict: Which One Should You Choose?</h3><p>There’s no one-size-fits-all answer. Choose based on your project requirements, team expertise, and long-term goals.</p><p>CriteriaReact NativeFlutterLanguageJavaScriptDartPerformanceGoodExcellentUI CustomizationModerate (native components)High (own rendering engine)Community &amp; EcosystemMatureRapidly growingMulti-Platform SupportMobile (Web optional)Mobile, Web, Desktop (official)</p><h3>✍️ Final Thoughts</h3><p>If you’re starting a project in 2025, both React Native and Flutter are solid choices. If your team is well-versed in React or you’re extending an existing app, React Native is a safe bet. On the other hand, if you’re building something from scratch and want beautiful, performant UIs across multiple platforms, Flutter might be the future-proof choice.</p><p>Ultimately, let your <strong>project’s needs</strong> and your <strong>team’s strengths</strong> guide your decision.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be6875850af8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Comprehensive Guide to Core React Hooks]]></title>
            <link>https://medium.com/@rahulkuma/a-comprehensive-guide-to-core-react-hooks-284cc1666c1b?source=rss-c92746bd5961------2</link>
            <guid isPermaLink="false">https://medium.com/p/284cc1666c1b</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react-hook]]></category>
            <dc:creator><![CDATA[Rahul kumar]]></dc:creator>
            <pubDate>Thu, 08 Aug 2024 10:10:10 GMT</pubDate>
            <atom:updated>2024-08-08T10:10:10.165Z</atom:updated>
            <content:encoded><![CDATA[<p>React Hooks, introduced in React 16.8, revolutionized how developers write components in React. Before Hooks, state management and side effects in functional components were nearly impossible, requiring the use of class components. Hooks brought in a paradigm shift, allowing functional components to be as powerful and feature-rich as class components. In this blog, we’ll delve deep into the core React Hooks: useState, useEffect, useContext, useReducer, useCallback, useMemo, and useRef.</p><ol><li><strong>useState: State Management Simplified</strong></li></ol><p>The useState hook allows you to add state to functional components. Before useState, state was only available in class components. Now, you can maintain and update state directly within functional components.</p><h4>Syntax:</h4><pre>const [state, setState] = useState(initialState);</pre><ul><li><strong>state</strong>: The current state value.</li><li><strong>setState</strong>: A function to update the state.</li><li><strong>initialState</strong>: The initial value of the state.</li></ul><p>Example:</p><pre>import React, { useState } from &#39;react&#39;;<br>function Counter() {<br>const [count, setCount] = useState(0);<br>return (<br>&lt;div&gt;<br>&lt;p&gt;You clicked {count} times&lt;/p&gt;<br>&lt;button onClick={() =&gt; setCount(count + 1)}&gt;Click me&lt;/button&gt;<br>&lt;/div&gt;<br>);<br>}</pre><p>In this example, useState initializes the count variable to 0. Every time the button is clicked, setCount updates the count state, causing the component to re-render with the new value.</p><p>2. <strong>useEffect: Managing Side Effects</strong></p><p>The useEffect hook lets you perform side effects in your components, such as data fetching, subscriptions, or manually changing the DOM. It can be thought of as a combination of componentDidMount, componentDidUpdate, and componentWillUnmount in class components.</p><pre>useEffect(() =&gt; {<br>  // Side-effect code here<br><br>  return () =&gt; {<br>    // Cleanup code here (optional)<br>  };<br>}, [dependencies]);</pre><p><strong>dependencies</strong>: An array of variables that the effect depends on. The effect runs only when these variables change.</p><p>Example:</p><pre>import React, { useState, useEffect } from &#39;react&#39;;<br><br>function DataFetcher() {<br>  const [data, setData] = useState(null);<br><br>  useEffect(() =&gt; {<br>    fetch(&#39;https://api.example.com/data&#39;)<br>      .then(response =&gt; response.json())<br>      .then(data =&gt; setData(data));<br>  }, []);<br><br>  return (<br>    &lt;div&gt;<br>      {data ? &lt;pre&gt;{JSON.stringify(data, null, 2)}&lt;/pre&gt; : &lt;p&gt;Loading...&lt;/p&gt;}<br>    &lt;/div&gt;<br>  );<br>}</pre><p>Here, useEffect fetches data when the component mounts. The empty dependency array [] ensures the effect runs only once, similar to componentDidMount.</p><p>3. <strong>useContext: Simplifying Context Usage</strong></p><p>The useContext hook simplifies consuming context in React components. Previously, using context required a combination of Context.Consumer and render props, but useContext makes this more straightforward.</p><p><strong>Syntax:</strong></p><pre>const contextValue = useContext(MyContext);</pre><p><strong>MyContext</strong>: The context you want to consume.</p><p><strong>Example:</strong></p><pre>import React, { useContext } from &#39;react&#39;;<br>import { ThemeContext } from &#39;./ThemeContext&#39;;<br><br>function ThemedButton() {<br>  const theme = useContext(ThemeContext);<br><br>  return &lt;button style={{ background: theme.background, color: theme.color }}&gt;Themed Button&lt;/button&gt;;<br>}</pre><p>In this example, useContext retrieves the current value of ThemeContext, making it easy to access the context without additional boilerplate.</p><p>4. <strong>useReducer: Complex State Management</strong></p><p>The useReducer hook is a more powerful alternative to useState, especially for managing complex state logic. It is similar to the Reducer function in Redux, where state changes are handled by a reducer function.</p><p><strong>Syntax:</strong></p><pre>const [state, dispatch] = useReducer(reducer, initialState);</pre><ul><li><strong>reducer</strong>: A function that determines the next state based on the current state and an action.</li><li><strong>initialState</strong>: The initial state of the component.</li><li><strong>dispatch</strong>: A function to send actions to the reducer.</li></ul><p><strong>Example:</strong></p><pre>import React, { useReducer } from &#39;react&#39;;<br><br>const initialState = { count: 0 };<br><br>function reducer(state, action) {<br>  switch (action.type) {<br>    case &#39;increment&#39;:<br>      return { count: state.count + 1 };<br>    case &#39;decrement&#39;:<br>      return { count: state.count - 1 };<br>    default:<br>      throw new Error();<br>  }<br>}<br><br>function Counter() {<br>  const [state, dispatch] = useReducer(reducer, initialState);<br><br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;Count: {state.count}&lt;/p&gt;<br>      &lt;button onClick={() =&gt; dispatch({ type: &#39;increment&#39; })}&gt;+&lt;/button&gt;<br>      &lt;button onClick={() =&gt; dispatch({ type: &#39;decrement&#39; })}&gt;-&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>This example uses useReducer to manage a counter. The reducer function handles state transitions based on the action type, offering more control over state management compared to useState.</p><p>5. <strong>useCallback: Memoizing Functions</strong></p><p>The useCallback hook memoizes a function, preventing its recreation on every render. This is useful when passing functions as props to child components, ensuring they aren’t recreated unnecessarily, which can cause performance issues.</p><p><strong>Syntax:</strong></p><pre>const memoizedCallback = useCallback(() =&gt; {<br>  // Function logic here<br>}, [dependencies]);</pre><p><strong>dependencies</strong>: The list of variables that the callback depends on. The function is recreated only if one of these variables changes.</p><p><strong>Example:</strong></p><pre>import React, { useState, useCallback } from &#39;react&#39;;<br><br>function ParentComponent() {<br>  const [count, setCount] = useState(0);<br><br>  const increment = useCallback(() =&gt; {<br>    setCount(c =&gt; c + 1);<br>  }, []);<br><br>  return &lt;ChildComponent increment={increment} /&gt;;<br>}<br><br>function ChildComponent({ increment }) {<br>  return &lt;button onClick={increment}&gt;Increment&lt;/button&gt;;<br>}</pre><p>In this example, useCallback ensures that the increment function is only recreated if the dependencies change, preventing unnecessary re-renders of the ChildComponent.</p><h3>6. <strong>useMemo: Optimizing Performance</strong></h3><p>The useMemo hook memoizes the result of a computation, recomputing it only when one of the dependencies changes. This is beneficial for expensive calculations that don’t need to be redone on every render.</p><p><strong>Syntax:</strong></p><pre>const memoizedValue = useMemo(() =&gt; computeExpensiveValue(a, b), [a, b]);</pre><p><strong>dependencies</strong>: The list of variables on which the computation depends. The value is recomputed only if one of these variables changes.</p><p><strong>Example:</strong></p><pre>import React, { useState, useMemo } from &#39;react&#39;;<br><br>function ExpensiveCalculationComponent({ a, b }) {<br>  const result = useMemo(() =&gt; {<br>    return a * b; // An example of a potentially expensive calculation<br>  }, [a, b]);<br><br>  return &lt;div&gt;Result: {result}&lt;/div&gt;;<br>}</pre><p>Here, useMemo prevents the recalculation of result unless a or b changes, optimizing the component’s performance.</p><p>7. <strong>useRef: Accessing DOM Elements and Persisting Values</strong></p><p>The useRef hook returns a mutable ref object, which persists across renders. It is often used to directly access DOM elements or to keep track of mutable values without triggering a re-render.</p><p><strong>Syntax:</strong></p><pre>const refContainer = useRef(initialValue);</pre><p><strong>initialValue</strong>: The initial value of the ref object.</p><p><strong>Example:</strong></p><pre>import React, { useRef } from &#39;react&#39;;<br><br>function TextInputWithFocusButton() {<br>  const inputEl = useRef(null);<br><br>  const handleClick = () =&gt; {<br>    inputEl.current.focus();<br>  };<br><br>  return (<br>    &lt;div&gt;<br>      &lt;input ref={inputEl} type=&quot;text&quot; /&gt;<br>      &lt;button onClick={handleClick}&gt;Focus the input&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>In this example, useRef is used to directly access the input element, allowing the button to focus the input when clicked.</p><p><strong>Conclusion</strong></p><p>React Hooks have fundamentally changed how developers build components in React. They enable functional components to manage state, handle side effects, and optimize performance, making them a powerful alternative to class components. Understanding and mastering these core hooks — useState, useEffect, useContext, useReducer, useCallback, useMemo, and useRef—is essential for building modern React applications.</p><p>Whether you’re refactoring an old class-based component or building a new one from scratch, these hooks provide the tools you need to create efficient, readable, and maintainable code. As you grow more comfortable with these hooks, you’ll find that they not only simplify your code but also make it more robust and performant.</p><h3>Upcoming</h3><p>Next blog on Custom Hooks: Reusable Logic.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=284cc1666c1b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding React Hooks]]></title>
            <link>https://medium.com/@rahulkuma/understanding-react-hooks-69b8ea895194?source=rss-c92746bd5961------2</link>
            <guid isPermaLink="false">https://medium.com/p/69b8ea895194</guid>
            <category><![CDATA[reactive-programming]]></category>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[useeffect]]></category>
            <dc:creator><![CDATA[Rahul kumar]]></dc:creator>
            <pubDate>Tue, 21 May 2024 07:06:52 GMT</pubDate>
            <atom:updated>2024-05-21T07:06:52.107Z</atom:updated>
            <content:encoded><![CDATA[<p>React Hooks have revolutionized how we write React applications by providing a powerful and flexible way to manage state and side effects in functional components. Introduced in React 16.8, Hooks allows developers to use state and other React features without writing class components. This blog will explore what React Hooks are, their purposes, and advantages, and how they enhance functional components compared to their class-based counterparts.</p><h3>What Are React Hooks?</h3><p>React Hooks are special functions that let you “hook into” React features. The most commonly used Hooks are:</p><ul><li>useState: Manages state in a functional component.</li><li>useEffect: Handles side effects such as data fetching and subscriptions.</li><li>useContext: Provides access to the React Context API, enabling global state management.</li><li>useReducer: Manages more complex state logic similar to Redux.</li><li>useMemo and useCallback: Optimize performance by memoizing values and functions.</li></ul><p>These Hooks enable functional components to handle state and lifecycle events, which were traditionally only possible in class components.</p><h3>Purpose of React Hooks</h3><p>The primary purpose of React Hooks is to simplify the use of state and side effects in functional components. Before Hooks, functional components were stateless and could only render UI based on props. Any state management or lifecycle logic required the use of class components. Hooks eliminate this constraint, making functional components more versatile and powerful.</p><h3>Advantages of React Hooks</h3><h3>1. Improved Code Readability</h3><p>Hooks make your code more readable and easier to understand by reducing the complexity associated with class components. In class components, lifecycle methods like componentDidMount, componentDidUpdate and componentWillUnmount often become bloated with unrelated logic. Hooks enable you to split these concerns into reusable functions.</p><p>For example:</p><pre>// Class component<br>class Example extends React.Component {<br>  state = { count: 0 };<br><br>  componentDidMount() {<br>    document.title = `Count: ${this.state.count}`;<br>  }<br><br>  componentDidUpdate() {<br>    document.title = `Count: ${this.state.count}`;<br>  }<br><br>  render() {<br>    return (<br>      &lt;button onClick={() =&gt; this.setState({ count: this.state.count + 1 })}&gt;<br>        Count: {this.state.count}<br>      &lt;/button&gt;<br>    );<br>  }<br>}<br><br>// Functional component with Hooks<br>import React, { useState, useEffect } from &#39;react&#39;;<br><br>function Example() {<br>  const [count, setCount] = useState(0);<br><br>  useEffect(() =&gt; {<br>    document.title = `Count: ${count}`;<br>  }, [count]);<br><br>  return (<br>    &lt;button onClick={() =&gt; setCount(count + 1)}&gt;<br>      Count: {count}<br>    &lt;/button&gt;<br>  );<br>}</pre><p>The functional component with Hooks is shorter, more readable, and separates side effects from the main logic.</p><h3>2. Enhanced Reusability</h3><p>Hooks allow for better reusability of logic across different components. Custom Hooks can be created to encapsulate and reuse stateful logic. For instance, if you have a form input validation logic, you can create a custom Hook for it:</p><pre>import { useState } from &#39;react&#39;;<br><br>function useInputValidation(initialValue) {<br>  const [value, setValue] = useState(initialValue);<br>  const [error, setError] = useState(null);<br><br>  const validate = (value) =&gt; {<br>    if (value.length &lt; 5) {<br>      setError(&#39;Input must be at least 5 characters long&#39;);<br>    } else {<br>      setError(null);<br>    }<br>  };<br><br>  const handleChange = (e) =&gt; {<br>    setValue(e.target.value);<br>    validate(e.target.value);<br>  };<br><br>  return { value, error, handleChange };<br>}<br><br>// Using the custom Hook in a component<br>function InputComponent() {<br>  const { value, error, handleChange } = useInputValidation(&#39;&#39;);<br><br>  return (<br>    &lt;div&gt;<br>      &lt;input value={value} onChange={handleChange} /&gt;<br>      {error &amp;&amp; &lt;p&gt;{error}&lt;/p&gt;}<br>    &lt;/div&gt;<br>  );<br>}</pre><p>This custom Hook encapsulates the validation logic, making it reusable across different input components.</p><h3>3. Simplified Lifecycle Management</h3><p>Managing component lifecycle methods can be cumbersome in class components, especially when dealing with multiple side effects. Hooks like useEffect simplify this by allowing you to handle side effects directly within the functional component, making it easier to manage and debug.</p><p>In class components, you might need multiple lifecycle methods to handle different side effects. With Hooks, you can handle them all in one place:</p><pre>useEffect(() =&gt; {<br>  // Side effect code<br>  console.log(&#39;Component mounted or updated&#39;);<br><br>  // Cleanup function<br>  return () =&gt; {<br>    console.log(&#39;Component will unmount&#39;);<br>  };<br>}, []);</pre><p>The above useEffect runs on mount and cleanup on unmount, providing a clear and concise way to handle side effects and their cleanup.</p><h3>Conclusion</h3><p>React Hooks have significantly enhanced the capabilities of functional components, making them as powerful as class components while providing a more intuitive and cleaner API. By improving code readability, enabling logic reusability, and simplifying lifecycle management, Hooks helps developers write more maintainable and efficient React applications.</p><p>Whether you are a newcomer to React or an experienced developer, embracing Hooks will undoubtedly lead to better-organized code and a more enjoyable development experience. So, dive into Hooks, experiment with custom Hooks, and see how they can transform your React projects.</p><h3><strong>Upcoming</strong></h3><p>Next blog on Core React Hooks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69b8ea895194" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Title: Mastering React Hooks: Unleashing the Power of Functional Components]]></title>
            <link>https://medium.com/@rahulkuma/title-mastering-react-hooks-unleashing-the-power-of-functional-components-463f679bae22?source=rss-c92746bd5961------2</link>
            <guid isPermaLink="false">https://medium.com/p/463f679bae22</guid>
            <category><![CDATA[react-hook]]></category>
            <dc:creator><![CDATA[Rahul kumar]]></dc:creator>
            <pubDate>Tue, 12 Dec 2023 13:49:35 GMT</pubDate>
            <atom:updated>2023-12-12T13:49:35.144Z</atom:updated>
            <content:encoded><![CDATA[<p>Introduction:<br>React Hooks have revolutionized the way developers manage state and side effects in React applications. With their introduction, functional components gained the ability to handle complex logic and lifecycle methods, simplifying code and improving reusability. In this blog post, we will dive deep into React Hooks, exploring their core concepts, best practices, and practical examples to help you master this powerful feature.</p><p>## Table of Contents<br>1. Understanding React Hooks<br> — What are Hooks?<br> — The Benefits of Hooks<br>2. Core React Hooks<br> — useState: Managing Component State<br> — useEffect: Handling Side Effects<br> — useContext: Accessing Context in Functional Components<br> — useRef: Referencing DOM Elements and Values<br>3. Custom Hooks: Reusable Logic<br>4. Best Practices for Working with Hooks<br> — Rules of Hooks<br> — Separating Concerns with Multiple Hooks<br> — Optimizing Performance with Memoization<br>5. Practical Examples and Code Snippets<br> — Building a Counter Component with useState<br> — Fetching Data with useEffect<br> — Implementing Dark Mode with useContext<br> — Managing Focus with useRef<br>6. Advanced Hooks and Libraries<br> — useReducer: Managing Complex State Transitions<br> — React Router Hooks: Navigating in React Applications<br> — Third-Party Custom Hooks and Libraries<br>7. Testing Hooks<br> — Testing useState and useEffect<br> — Mocking Dependencies and Side Effects<br>8. Conclusion</p><p>## Section 1: Understanding React Hooks<br>In this section, we will introduce React Hooks, explaining their purpose, advantages, and how they enhance functional components compared to class components. We will highlight the benefits of improved code readability, reusability, and simplified lifecycle management.</p><p>## Section 2: Core React Hooks<br>This section will cover the core React Hooks: useState, useEffect, useContext, and useRef. For each hook, we will provide a detailed explanation, practical examples, and code snippets. We will demonstrate how to leverage useState for managing component state, useEffect for handling side effects, useContext for accessing context, and useRef for referencing DOM elements and values.</p><p>## Section 3: Custom Hooks: Reusable Logic<br>In this section, we will explore the concept of custom hooks. Custom hooks allow us to extract and reuse common logic across multiple components. We will guide you through creating your own custom hooks, discuss best practices, and showcase real-world examples.</p><p>## Section 4: Best Practices for Working with Hooks<br>To ensure efficient and maintainable code, following best practices is crucial. This section will cover important guidelines for working with hooks, including the rules of hooks, separating concerns with multiple hooks, and optimizing performance through memoization techniques.</p><p>## Section 5: Practical Examples and Code Snippets<br>This section will provide practical examples and code snippets to solidify your understanding of React Hooks. We will demonstrate building a counter component using useState, fetching data with useEffect, implementing dark mode using useContext, and managing focus with useRef.</p><p>## Section 6: Advanced Hooks and Libraries<br>For developers seeking more advanced use cases, this section will explore additional hooks and libraries. We will cover useReducer for managing complex state transitions, React Router Hooks for navigation in React applications, and showcase popular third-party custom hooks and libraries.</p><p>## Section 7: Testing Hooks<br>Properly testing hooks is essential to ensuring their correctness and reliability. This section will delve into testing useState, useEffect, and custom hooks. We will cover strategies for mocking dependencies and side effects, and provide insights on effective testing practices.</p><p>## Conclusion<br>In conclusion, React Hooks have revolutionized the way we write React components. With their simplicity, reusability, and improved lifecycle management, hooks have become an essential tool for modern React development. By mastering React Hooks, you can elevate your skills as a developer, write cleaner and more efficient code, and unlock the full potential of functional components in your React applications.</p><p>In the blog post, we aim to provide comprehensive explanations, practical examples, and code snippets to guide you on your journey to becoming a React Hooks expert. So, grab your editor and get ready to dive into the wonderful world of React Hooks!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=463f679bae22" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ReactJS: Empowering Software Engineers to Build Remarkable Web Applications]]></title>
            <link>https://medium.com/@rahulkuma/reactjs-empowering-software-engineers-to-build-remarkable-web-applications-c8692ec1b45e?source=rss-c92746bd5961------2</link>
            <guid isPermaLink="false">https://medium.com/p/c8692ec1b45e</guid>
            <category><![CDATA[use-of-react]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[why-react]]></category>
            <category><![CDATA[react-features]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Rahul kumar]]></dc:creator>
            <pubDate>Tue, 18 Jul 2023 10:07:27 GMT</pubDate>
            <atom:updated>2023-07-18T10:07:27.048Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Introduction:</strong> As a software engineer, I have always been on the lookout for technologies that streamline the development process and allow me to create outstanding web applications. ReactJS, a popular JavaScript library developed by Facebook, has been a game-changer in the world of web development. In this blog post, I will share my experiences and insights as a software engineer working with ReactJS, highlighting its benefits, key features, and why it’s a must-have tool in every developer’s arsenal.</p><ol><li><strong>Streamlining Development with ReactJS: </strong>ReactJS introduces a component-based architecture that brings order and structure to the development process. As a software engineer, this modular approach has been a game-changer for me. I can break down complex user interfaces into reusable components, making the code more manageable, scalable, and easier to maintain. With ReactJS, I can build applications faster, without sacrificing quality or performance.</li><li><strong>The Power of the Virtual DOM:</strong> ReactJS’s Virtual DOM is a revolutionary concept that has significantly improved the efficiency of web applications. Unlike traditional JavaScript frameworks, ReactJS doesn’t directly manipulate the browser’s DOM. Instead, it creates a virtual representation of the DOM, allowing for efficient updates and minimizing unnecessary re-renders. This approach results in faster rendering, smoother user interactions, and an overall enhanced user experience.</li><li><strong>Declarative Programming:</strong> Making Life Easier for Developers: One of the standout features of ReactJS is its declarative programming model. As a software engineer, I appreciate how React allows me to focus on describing what the UI should look like, rather than worrying about the underlying implementation details. By managing application state and using props, React handles the updates and re-renders automatically, saving me valuable time and reducing the chance of introducing bugs.</li><li><strong>React Ecosystem:</strong> Abundance of Tools and Libraries: The React ecosystem is a treasure trove of tools, libraries, and resources that simplify development and enhance productivity. From state management solutions like Redux or MobX to UI component libraries like Material-UI or Ant Design, the React ecosystem offers a wide range of options to cater to various development needs. The active community surrounding React ensures continuous improvements, frequent updates, and a wealth of knowledge-sharing.</li><li><strong>React Native:</strong> Extending Reach to Mobile Development: React Native, built on top of ReactJS, extends the power of React to mobile app development. With React Native, I can leverage my existing knowledge of ReactJS to build native mobile applications using JavaScript. This cross-platform framework allows for code reuse, speeding up the development process and enabling me to reach a broader audience across multiple platforms.</li><li><strong>Continuous Learning and Growth:</strong> As a software engineer, I believe in the importance of continuous learning and staying up-to-date with the latest technologies. ReactJS provides ample opportunities for growth through its active community, online tutorials, documentation, and real-world projects. By embracing ReactJS, I have been able to expand my skill set, enhance my problem-solving abilities, and stay relevant in the ever-evolving field of web development.</li></ol><p><strong>Conclusion: </strong>As a software engineer, ReactJS has been a transformative tool in my web development journey. Its component-based architecture, virtual DOM, declarative programming, and vast ecosystem of tools and libraries have empowered me to build remarkable web applications efficiently. By embracing ReactJS and staying engaged with its thriving community, software engineers like myself can unlock endless possibilities and deliver exceptional user experiences. So, if you’re a fellow software engineer, I highly recommend exploring ReactJS and witnessing its potential firsthand.</p><p>Stay Tuned for the upcoming blog, <strong>Mastering React Hooks</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8692ec1b45e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>