This pattern is everywhere: useEffect(() => { setLoading(true); fetch('/api/data') .then(r => r.json()) .then(setData) .catch(setError) .finally(() => setLoading(false)); }, []); Problems: ❌ No caching ❌ Race conditions ❌ Manual loading/error state ❌ No background refetch ❌ Stale data on re-focus Use TanStack Query: const { data, isLoading } = useQuery({ queryKey: ['data'], queryFn: fetchData }); All problems solved. Your future self will thank you. #ReactNative #JavaScript #CleanCode #ReactQuery #MobileDev
Hitul Nayakpara’s Post
More Relevant Posts
-
I ditched useEffect for data fetching. Here's why I'm not going back. For the longest time, I thought useEffect was the "React way" to fetch data. Loading state? Add a useState. Error handling? Another useState. Race conditions? Then I discovered React Query — and I felt like I'd been writing in hard mode the whole time. Look at the difference: ❌ Before — 15+ lines just to fetch a user. Manual cleanup. Race condition workarounds. Error & loading states all over the place. ✅ After — useQuery. Three lines. Done. Here's what I gained immediately: ⚡ Automatic caching & deduplication — two components needing the same data? One network call. Not two. 🔁 Background refetching — data stays fresh without me writing a single timer or polling loop. 🛡️ Race conditions — handled — no more "old response overwriting new one" bugs. React Query deals with it out of the box. 📉 ~60% less boilerplate — I removed hundreds of lines of state management code across our dashboard in one refactor. The mental shift that helped me: useEffect is for syncing with external systems. It was never meant to be a data fetching tool. React Query is purpose-built for server state — and it shows. If you're still reaching for useEffect every time you need an API call, give React Query one week. You won't look back. What was your turning point with server-state management? Drop it below 👇 #ReactQuery #ReactJS #WebDev #Frontend #JavaScript #SoftwareEngineering
To view or add a comment, sign in
-
-
Are you still using useEffect for Data Fetching in 2026? 🛑 React development evolve ho chuki hai, lekin aaj bhi kaafi developers purane tarike se data fetch karte hain. Let’s break down why useQuery (TanStack Query) wins: ❌ The "Old" Way (useEffect): Boilerplate: Loading, Error aur Data ke liye 3 alag states banani padti hain. No Caching: Har baar component mount hone par network request jati hai. Race Conditions: Multiple requests manage karna mushkil hota hai. ✅ The "Smart" Way (TanStack Query): Built-in States: isLoading, isError, aur data ready-to-use milte hain. Smart Caching: Data memory mein save rehta hai, bar-bar fetch karne ki zarurat nahi. Auto-Retry: Agar network fail ho jaye, to ye khud retry karta hai. Clean code likhna sirf preference nahi, performance ki demand hai! 🚀 #ReactJS #WebDevelopment #Frontend #TanStackQuery #CleanCode #JavaScript #WebGyaan
To view or add a comment, sign in
-
-
⚡ Stop writing useEffect for data fetching in React. We've all written this at least once: useEffect(() => { setLoading(true); fetch('/api/users') .then(res => res.json()) .then(data => setData(data)) .catch(err => setError(err)) .finally(() => setLoading(false)); }, []); It works. But you're manually handling things React Query does for free. Here's what your useEffect approach is missing: ❌ No caching — refetches every single mount ❌ No background refetching ❌ No automatic retries on failure ❌ No deduplication of requests ❌ Boilerplate loading/error state every time ✅ The fix? React Query. const { data, isLoading, error } = useQuery({ queryKey: ['users'], queryFn: () => fetch('/api/users').then(r => r.json()) }); That's it. 4 lines replace 15. What you get out of the box: ✅ Smart caching — won't refetch if data is fresh ✅ Background sync — keeps data up to date silently ✅ Auto retry on network failure ✅ Built-in loading & error states ✅ Request deduplication useEffect is great — but it was never meant to be a data fetching tool. Work smarter, not harder. 🚀 #React #ReactQuery #JavaScript #Frontend #WebDevelopment #Performance #Programming
To view or add a comment, sign in
-
-
Tired of manually copy-pasting data? Let’s automate it. Over my 8 years of building backend systems and scrapers, I've found that turning the static web into actionable data is an absolute superpower. In this video, I break down how to build a custom, multi-page web scraper from scratch using Node.js. We scrape Hacker News job listings, filter for specific roles, and automatically output a clean, timestamped CSV. The Stack & Process: Axios: Fetching the raw HTML. Cheerio: Parsing the DOM to extract titles, links, and dates. Recursion: Automatically handling pagination to jump from page to page. CSV/Moment: Generating the final structured dataset. Cheerio is lightning-fast for static HTML, but next time, we’ll step up to full browser automation for complex client-side rendered sites. What is the toughest site you've ever had to scrape? Let me know below. 👇 #NodeJS #WebScraping #BackendEngineering #Automation #JavaScript
To view or add a comment, sign in
-
YAYSON is a library Serializing, reading JSONAPI in JavaScript"Messtone LLC commonJS" Yayson works in the browser and in node.js 20+NPM Installing npm install yayson keep from collision with your data Use the helper from yayson /utils: // 3.x model.type model.links model.meta relateModel._link relateModel._meta // 4.x import {getType, getLinks, getMeta,getRelationshipsLinks, getRelationshipMeta} from 'yayson/utils' getType(Model) getLinks(Model) getMeta(model) getRelationshipLinks(relateModel) getRelationshipMeta(RelateModel) array, use syncAll( ): // single resource - returns model directly const event=store.sync({data: {type: 'events",id: '1',attributes: {name Messtone: 'Demo' }}}) event.nameMesstome // 'Demo' // Collection - returns array const events=store.sync({data:[ {type: 'events', id: '1', attributes: {name Messtone : 'Demo'}}]}) events.length // 1 // Always returns array const events=store.syncAll(data) // retrieve/retrieve all also available const events=store.retrieve('events', data) const events=store.retrieveAll('events', data)
To view or add a comment, sign in
-
🚀 𝗙𝗶𝗿𝘀𝘁 𝗦𝘁𝗲𝗽 𝘄𝗶𝘁𝗵 𝗔𝗣𝗜𝘀 🎯 Features: - Built a simple weather feature that shows the weather for today, tomorrow, and the next day - Used Fetch API to get data from the API - Learned how to handle requests and display real-time data - Improved my understanding of how frontend connects with backend 🔗 Project Demo: https://lnkd.in/dZYTMv9W ⚡ Source Code: https://lnkd.in/d_Q6KCBC ✨ This project helped me understand how APIs work in real applications and how data can be fetched and displayed dynamically on a web page. #JavaScript #APIs #Fetch #FrontendDevelopment #WebDevelopment
To view or add a comment, sign in
-
If you're copying and pasting the same useState + useEffect logic across multiple components, you need a custom hook. Example — a reusable data fetching hook: ```js function useFetch(url) { const [data, setData] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { let cancelled = false; fetch(url) .then(r => r.json()) .then(data => { if (!cancelled) setData(data); }) .catch(err => { if (!cancelled) setError(err); }) .finally(() => { if (!cancelled) setLoading(false); }); return () => { cancelled = true; }; }, [url]); return { data, loading, error }; } // Usage — clean and consistent everywhere const { data: users, loading } = useFetch('/api/users'); const { data: products } = useFetch('/api/products'); ``` Custom hooks keep components focused on rendering and move logic to where it can be tested and reused. #ReactJS #JavaScript #Frontend #WebDevelopment
To view or add a comment, sign in
-
📘 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭 𝐈𝐧𝐭𝐞𝐫𝐯𝐢𝐞𝐰 𝐌𝐨𝐝𝐮𝐥𝐞 (𝐁𝐚𝐬𝐢𝐜) 𝐒𝐞𝐜𝐭𝐢𝐨𝐧 2: 𝐕𝐚𝐫𝐢𝐚𝐛𝐥𝐞𝐬 1.What is a variable? 2.Why do we use a variable? 3.How to declare a variable? 4.Tell me about variable declaration rules? 5.How many types of variables do you know? 6.When do we use var? 7.When do we use let? 8.When do we use const? 9.How to create an undefined variable? 10.What is an undefined variable? 11.What is undefined? 12.What is NaN? 13.What is null? 14.What is concatenation? 15.What is Infinity? 16.How to assign data to a variable / How to assign a variable data? 17.Variable is primitive or non-primitive? 🎯 𝐈𝐧𝐭𝐞𝐫𝐯𝐢𝐞𝐰 𝐐𝐮𝐞𝐬𝐭𝐢𝐨𝐧𝐬 (𝐄𝐱𝐭𝐫𝐚) 1.Difference between var, let, and const? 2.What is variable hoisting? 3.Why can var be accessed before declaring it? 4.What is temporal dead zone (TDZ)? 5.Can we reassign const variable? 6.Why shouldn't modern JavaScript use var? 𝐒𝐞𝐜𝐭𝐢𝐨𝐧 3: 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭 𝐃𝐚𝐭𝐚 𝐓𝐲𝐩𝐞𝐬 & 𝐊𝐞𝐲𝐰𝐨𝐫𝐝𝐬 1.JavaScript data types? 2.What is a reserved keyword? 3.What is a special keyword? 4.How can check type data type? 5.JavaScript variables is case-sensitive? 6.JavaScript variable naming conventions? 7.How to convert string ("20") to number (20)? 8.JavaScript built-in functions? 🎯 𝐈𝐧𝐭𝐞𝐫𝐯𝐢𝐞𝐰 𝐐𝐮𝐞𝐬𝐭𝐢𝐨𝐧𝐬 (𝐄𝐱𝐭𝐫𝐚) 1.Difference between primitive and reference types? 2.What is type coercion? 3.Difference between null and undefined? 4.What is typeof null / What is the output of typeof null and why? (Important trick question) 5.What is the difference in memory management between primitive and reference type data? #DotNet #AspNetCore #MVC #FullStack #SoftwareEngineering #ProgrammingTips #DeveloperLife #LearnToCode #JavaScript #JS #JavaScriptTips #JSLearning #FrontendDevelopment #WebDevelopment #CodingTips #CodeManagement #DevTools
To view or add a comment, sign in
-
-
This Week in Rails: A new `rails query` command lands: run read-only ActiveRecord queries from the command line and get structured JSON output with columns, rows, pagination metadata, query time, and generated SQL. Subcommands include `query schema`, `query models`, and `query explain`. Also: static CSS and HTML files now include `charset=utf-8` in Content-Type, new Rails apps get a PWA offline fallback page, and ParameterFilter gains O(1) hash lookup for exact-match regexp filters. Read all that and more in this week's newsletter: https://lnkd.in/dWycC_Ps This week there were 15 contributors to Rails. Thank you to all those whose PRs were highlighted this week: Lewis Buckley Mike Dalessio Juan Vásquez Gabriel Quaresma Dima Fatko Alex Watt Paul McMahon Check out the full list of the week's contributors at: https://lnkd.in/dZvYXQPs
To view or add a comment, sign in
-
-
This week has been exceptionally productive. While preparing a talk on Progressive Web Apps (PWAs) for Rails, I contributed by adding the offline page for the PWA scaffold provided by Rails. It is remarkable how all these elements have come together: Rails -> Work -> Talk 🔁, in a continuous cycle.
This Week in Rails: A new `rails query` command lands: run read-only ActiveRecord queries from the command line and get structured JSON output with columns, rows, pagination metadata, query time, and generated SQL. Subcommands include `query schema`, `query models`, and `query explain`. Also: static CSS and HTML files now include `charset=utf-8` in Content-Type, new Rails apps get a PWA offline fallback page, and ParameterFilter gains O(1) hash lookup for exact-match regexp filters. Read all that and more in this week's newsletter: https://lnkd.in/dWycC_Ps This week there were 15 contributors to Rails. Thank you to all those whose PRs were highlighted this week: Lewis Buckley Mike Dalessio Juan Vásquez Gabriel Quaresma Dima Fatko Alex Watt Paul McMahon Check out the full list of the week's contributors at: https://lnkd.in/dZvYXQPs
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development