SShortSingh.
Back to feed

How to Fetch API Data in React Using useEffect, useState, and Async/Await

0
·2 views

A tutorial on DEV Community walks beginners through fetching external API data inside React components using the FakeStoreAPI as a practical example. The guide first explains how JavaScript's native fetch() works with .then() promise chains, then shows how async/await simplifies the same logic with cleaner, more readable syntax. It demonstrates the correct React pattern of placing fetch calls inside the useEffect hook combined with useState to store results, avoiding infinite render loops. The tutorial also covers managing loading and error states to build a more resilient user interface. A common beginner mistake — marking the useEffect callback itself as async — is highlighted and explained, with the recommended fix of defining a separate async function inside the hook.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

Oracle Patch Naming Explained: RU, MRP, CSPU and What Matters in 2026

Oracle's database patching terminology has long confused administrators due to overlapping and evolving acronym names spanning more than a decade. The Release Update (RU) is now the primary quarterly patch bundle, combining security, regression, and functional fixes, with version 19.26.0.0.0 representing the 26th such update for Oracle 19c. The older RUR (Release Update Revision) track, once marketed as a conservative security-only alternative, was deprecated and discontinued after January 2023. Monthly Recommended Patches (MRP) have replaced RURs for cumulative fixes between quarterly releases, while a new monthly Critical Security Patch Update (CSPU) was introduced in 2026 to deliver security fixes between quarterly dates. Oracle's current guidance is straightforward: stay current on the latest RU, as falling behind makes future patching more difficult, not less.

0
ProgrammingDEV Community ·

How Chess Can Be Used as a Tool to Teach Core Math Concepts

Chess and mathematics share strong conceptual links, making the game a practical tool for math education. Research indicates that early exposure to chess can improve children's performance in math and science. The game helps students grasp concepts such as geometry, algebra, probability, combinatorics, and pattern recognition in an interactive way. Algebraic notation used in chess recording, for instance, familiarises students with symbolic reasoning, while piece movements illustrate geometric principles. Educators integrating chess into curricula report gains not only in mathematical ability but also in critical thinking and problem-solving skills.

0
ProgrammingDEV Community ·

Developer Releases Fluent AI SDK for Node Apps Supporting Google, OpenAI and Anthropic

A developer has launched an open-source SDK called ai-persona, designed to simplify AI integration in Node.js applications. The tool provides a fluent interface and an interactive CLI, allowing developers to add customizable AI functionality in seconds. It eliminates the need for writing lengthy boilerplate code or configuring complex local data pipelines. The SDK supports three major AI providers: Google, OpenAI, and Anthropic. It is publicly available via the npm package registry under the handle @yashu_jaat01/ai-persona.

0
ProgrammingDEV Community ·

Developers in 2026 weigh jobs, freelancing, and startups as income paths

Programmers today have multiple avenues to earn income, including traditional employment, freelancing, and building their own products or startups. While launching personal products has become more accessible, the quality and market fit of those products remains a significant challenge. Freelancing offers flexibility but comes with intense competition, whereas selling pre-built solutions can be lucrative if clients can be found. Starting a startup is currently the most popular route, though it demands a genuinely compelling idea to attract users beyond the founder. Ultimately, some in the developer community suggest that passion-driven work may be as important as strategy when choosing a path.