Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To resolve a React data-fetching issue, trace one request from the component to the server and back: inspect the browser’s Network panel and console, verify the exact URL and method, check the HTTP status and response body, then fix the layer where the failure occurs. A 404, a CORS block, a stale result from an earlier request, and a request that never starts are different problems—and need different fixes.

Start with the request in your browser

Open your browser’s developer tools and inspect both the Console and Network panels. Find the request your component is supposed to make, then check:

  • Whether the request was sent at all.
  • The final URL, HTTP method, query parameters, and request headers.
  • Whether credentials are included, if the endpoint requires them.
  • The status code, response content type, and response body.
  • Any console message about a network error, blocked request, or failed parsing.

If the request does not appear in Network, investigate the code path that should trigger it, including whether the component rendered and whether an Effect ran. If it appears, the status and response usually narrow the problem to the endpoint, browser policy, or response handling.

A request succeeding in a command-line client does not prove that browser JavaScript can read its response. Browsers enforce cross-origin rules that non-browser clients generally do not. MDN explains how the browser applies these rules in its CORS guide.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Handle 404 and other HTTP errors explicitly

fetch() usually resolves to a Response even when the server returns an HTTP error such as 404 or 500. It does not reject just because the status is unsuccessful. Check response.ok—true for a 2xx status—or inspect response.status before treating the response body as successful data. See MDN’s Fetch API guide.

By contrast, a request may reject when it fails before a readable HTTP response is available, such as for a network error or malformed request URL. Keep status handling distinct from request failures and from errors that occur while parsing the response body.

async function fetchJson(url) {
  const response = await fetch(url);

  if (!response.ok) {
    const detail = await response.text();
    throw new Error(`Request failed (${response.status}): ${detail}`);
  }

  return response.json();
}

This example preserves the server’s response text in the thrown error, which can help with diagnosis. Adapt error-body handling to the API: some endpoints return JSON errors, some return text, and some return an empty body. If response.json() fails, that is a parsing error—not the same as a failed HTTP status.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Fix cross-origin requests at the server boundary

When a browser request crosses origins, the API must return CORS headers permitting the requesting origin. For a non-simple request, the browser may first send a preflight request; inspect that request too, and confirm the server permits the intended origin, method, and headers. A CORS failure can prevent JavaScript from accessing the response, so the browser may expose less diagnostic detail to your code than you expect.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For requests that include credentials, the server must explicitly allow the requesting origin and agree to credentialed access. A wildcard allowed origin is not valid for credentialed access. Configure the API’s CORS policy to match the application’s actual origin and request requirements.

Setting mode: "no-cors" is not a general fix for a JSON API. It yields an opaque response whose body and headers your application JavaScript cannot read. Correct the server’s CORS configuration, or use an application-controlled server-side proxy when that fits the architecture.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Prevent an earlier request from replacing newer data

A common React bug occurs when a request depends on a changing value—such as a selected user or search query—and an earlier, slower request finishes after a newer one. Its result can then overwrite the data for the current selection.

React runs an Effect again when its reactive dependencies change, cleaning up the previous Effect before starting the next one. Include every prop, state value, and component-local value used by the Effect in its dependency array. In cleanup, mark the previous request as no longer current and apply its result only if it still belongs to the active Effect. React documents this cleanup-guard pattern in its useEffect reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
useEffect(() => {
  let ignore = false;

  async function load() {
    setLoading(true);
    setError(null);

    try {
      const response = await fetch(`/api/users/${userId}`);
      if (!response.ok) {
        throw new Error(`Request failed (${response.status})`);
      }
      const user = await response.json();
      if (!ignore) setUser(user);
    } catch (error) {
      if (!ignore) setError(error);
    } finally {
      if (!ignore) setLoading(false);
    }
  }

  load();
  return () => { ignore = true; };
}, [userId]);

Here, changing userId cleans up the prior Effect, so its eventual result cannot update the component. Keep loading, error, and displayed data consistent with the current request identity. Do not silence dependency warnings to conceal a dependency mismatch; restructure the Effect or move work that is not caused by rendering out of it. React’s guide You Might Not Need an Effect explains when an Effect is unnecessary.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose where data fetching belongs

Fetching directly in an Effect is workable for a small client-only request when you handle loading, errors, dependencies, and stale responses. It is manual: it does not fetch during server rendering, may create parent-child network waterfalls, and does not automatically provide caching or preloading. React recommends using a framework’s data-fetching mechanism where available, or a client-side cache when appropriate.

Approach Useful when Trade-offs to assess
Fetch in useEffect A client-only component needs a straightforward request tied to current props or state. You implement request lifecycle state, dependency correctness, stale-result protection, and any caching you need; it does not fetch during server rendering and can contribute to waterfalls.
Framework loader or integrated server data mechanism Data belongs to a route or page, or should be available during server rendering. Follow the framework’s version-specific conventions and understand its caching and revalidation behavior.
Client-side cache such as TanStack Query or useSWR Client interactions need caching, request deduplication, revalidation, or reuse across component lifecycles. Compare cache keys, invalidation, loading and error semantics, server-rendering support, and fit with the application’s existing conventions.

React lists TanStack Query, useSWR, and React Router 6.4+ as examples of data-fetching approaches; that list is illustrative, not a ranking. Choose based on where fetching runs, route integration, caching and invalidation needs, preloading or waterfall avoidance, and how much request lifecycle code you want to maintain. See React’s Effect guidance.

When server components are relevant

React Server Components can load data in a server environment and may avoid a client-only follow-up request for suitable data. Availability and setup depend on the framework and runtime. Follow the supported integration for your framework and its version; React notes that some underlying Server Component integration APIs are not subject to semver stability in the same way as component APIs. See the Server Components reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Do not use a Server Function as a general-purpose read or query endpoint. React describes Server Functions as mutation-oriented and says they are not recommended for fetching data; see the use server reference.

Match the symptom to the next check

  • No request in Network: verify that the component and triggering code path run, and that the Effect’s dependencies or event handler match the intended behavior.
  • 404 or 500 in Network: confirm the URL, method, and parameters, then inspect the response body. Handle the status explicitly in code.
  • Request works outside the browser but fails in it: inspect the browser console and any preflight request; check the API’s CORS policy for the application origin, method, headers, and credentials.
  • Data appears for the wrong selection or query: check the Effect dependencies and prevent results from cleaned-up requests from being committed.
  • Status is successful but data is missing or malformed: inspect the response body and content type, then handle parsing errors separately from HTTP errors.

The exact fix depends on the failing request and application architecture. For a targeted diagnosis, collect the request URL and method, status, console message, response body, relevant component and fetch-helper code, framework, and server CORS configuration.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.