<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Akhildas</title>
    <description>The latest articles on DEV Community by Akhildas (@akhildas675).</description>
    <link>https://dev.to/akhildas675</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1214372%2F655e89ad-175f-4b6b-906d-bc5fd101c50a.jpg</url>
      <title>DEV Community: Akhildas</title>
      <link>https://dev.to/akhildas675</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/akhildas675"/>
    <language>en</language>
    <item>
      <title>Stop Using useEffect for Data Fetching — Try TanStack Query Instead</title>
      <dc:creator>Akhildas</dc:creator>
      <pubDate>Sun, 06 Jul 2025 09:29:58 +0000</pubDate>
      <link>https://dev.to/akhildas675/stop-using-useeffect-for-data-fetching-try-tanstack-query-instead-5ejd</link>
      <guid>https://dev.to/akhildas675/stop-using-useeffect-for-data-fetching-try-tanstack-query-instead-5ejd</guid>
      <description>&lt;p&gt;If your React components are littered with useEffect hooks just to fetch data, it’s time to level up your approach.&lt;/p&gt;

&lt;p&gt;React has given us a lot of power with useEffect, but with great power comes great... boilerplate.&lt;/p&gt;

&lt;p&gt;Let’s face it — using useEffect for data fetching often ends up messy. We handle loading states, errors, cancellations, caching, refetching, and sometimes race conditions... manually. It’s a lot.&lt;/p&gt;

&lt;p&gt;Enter TanStack Query (formerly React Query) — a game-changer for handling async data in React apps.&lt;/p&gt;

&lt;p&gt;The Problem with useEffect for Fetching Data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Here’s what a typical useEffect data fetch looks like

import { useState, useEffect } from 'react';

const Users = () =&amp;gt; {
  const [users, setUsers] = useState([]);
  const [loading, setLoading] = useState(true);
  const [error, setError] = useState(null);

  useEffect(() =&amp;gt; {
    const controller = new AbortController();

    const fetchUsers = async () =&amp;gt; {
      try {
        const res = await fetch('/api/users', { signal: controller.signal });
        const data = await res.json();
        setUsers(data);
      } catch (err) {
        if (err.name !== 'AbortError') setError(err);
      } finally {
        setLoading(false);
      }
    };

    fetchUsers();

    return () =&amp;gt; controller.abort(); // cleanup
  }, []);

  if (loading) return &amp;lt;p&amp;gt;Loading...&amp;lt;/p&amp;gt;;
  if (error) return &amp;lt;p&amp;gt;Error: {error.message}&amp;lt;/p&amp;gt;;

  return (
    &amp;lt;ul&amp;gt;
      {users.map(u =&amp;gt; &amp;lt;li key={u.id}&amp;gt;{u.name}&amp;lt;/li&amp;gt;)}
    &amp;lt;/ul&amp;gt;
  );
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This looks okay — until you scale. Then you deal with:&lt;/p&gt;

&lt;p&gt;Multiple API calls&lt;br&gt;
Caching concerns&lt;br&gt;
Race conditions&lt;br&gt;
Data syncing&lt;br&gt;
Window refocus or re-fetching logic&lt;br&gt;
Manual error boundaries&lt;br&gt;
You get the idea.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The TanStack Query Way 🚀&lt;/strong&gt;&lt;br&gt;
Now, here’s the same thing using TanStack Query:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install @tanstack/react-query&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useQuery } from '@tanstack/react-query';

const fetchUsers = async () =&amp;gt; {
  const res = await fetch('/api/users');
  if (!res.ok) throw new Error('Network response was not ok');
  return res.json();
};

const Users = () =&amp;gt; {
  const { data, isLoading, error } = useQuery({
    queryKey: ['users'],
    queryFn: fetchUsers,
  });

  if (isLoading) return &amp;lt;p&amp;gt;Loading...&amp;lt;/p&amp;gt;;
  if (error) return &amp;lt;p&amp;gt;Error: {error.message}&amp;lt;/p&amp;gt;;

  return (
    &amp;lt;ul&amp;gt;
      {data.map(u =&amp;gt; &amp;lt;li key={u.id}&amp;gt;{u.name}&amp;lt;/li&amp;gt;)}
    &amp;lt;/ul&amp;gt;
  );
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That’s it.&lt;/p&gt;

&lt;p&gt;No state management.&lt;br&gt;
No useEffect.&lt;br&gt;
No AbortController.&lt;br&gt;
No complex cleanup logic.&lt;/p&gt;

&lt;p&gt;🚀 Why TanStack Query Rocks&lt;br&gt;
Here’s what you get out of the box:&lt;/p&gt;

&lt;p&gt;⭐ Automatic caching&lt;br&gt;
⭐ Background refetching&lt;br&gt;
⭐ Pagination and infinite queries&lt;br&gt;
⭐ Optimistic updates&lt;br&gt;
⭐ Retry logic&lt;br&gt;
⭐ Query invalidation&lt;br&gt;
⭐ Devtools for debugging&lt;br&gt;
⭐ SSR support&lt;br&gt;
⭐ Works with any data-fetching library (Axios, fetch, GraphQL, etc.)&lt;/p&gt;

&lt;p&gt;💡 When Should You Use TanStack Query?&lt;br&gt;
Use it when:&lt;/p&gt;

&lt;p&gt;You’re building anything beyond a simple static app.&lt;br&gt;
You need multiple API calls or shared data.&lt;br&gt;
You want to avoid manually managing loading/error states.&lt;br&gt;
You want a reactive and declarative approach to fetching.&lt;br&gt;
But keep in mind: if you’re just calling localStorage or don’t want caching, useEffect is still fine.&lt;/p&gt;

&lt;p&gt;🧠 Final Thoughts&lt;br&gt;
React gave us the tools. TanStack Query gives us the power.&lt;/p&gt;

&lt;p&gt;By replacing manual useEffect data fetching with TanStack Query, you're writing cleaner, faster, and more scalable React apps. It’s a mindset shift — from imperative to declarative data fetching.&lt;/p&gt;

&lt;p&gt;Don’t just fetch data. Query it intelligently.&lt;/p&gt;

</description>
      <category>react</category>
      <category>node</category>
      <category>typescript</category>
      <category>tanstack</category>
    </item>
    <item>
      <title>The Mistake of Wrong Planning 😔</title>
      <dc:creator>Akhildas</dc:creator>
      <pubDate>Mon, 31 Mar 2025 08:04:17 +0000</pubDate>
      <link>https://dev.to/akhildas675/the-mistake-of-wrong-planning-333c</link>
      <guid>https://dev.to/akhildas675/the-mistake-of-wrong-planning-333c</guid>
      <description>&lt;p&gt;After high school, I joined BCom, believing I had my future well planned. At first, I was excited and confident. But as time passed, I started losing interest.&lt;/p&gt;

&lt;p&gt;I didn’t realize it immediately, but slowly, I understood that my plan was not right. I had chosen a path without truly knowing if it was the right fit for me. I followed the usual path without questioning if it suited me.&lt;/p&gt;

&lt;p&gt;Through different situations and experiences, I faced the reality that a plan can be wrong. I had to accept that my decision wasn’t working out the way I expected.&lt;/p&gt;

&lt;p&gt;💡 Lesson learned: A plan made without real understanding can lead to confusion and regret. Planning is not just about making decisions—it’s about making the right ones.&lt;/p&gt;

&lt;p&gt;❓ Have you ever made a wrong plan in life? What did you learn from it? Drop your thoughts below! 👇&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>career</category>
    </item>
  </channel>
</rss>
