Click here to Skip to main content
15,798,066 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Team

I am getting this exception when inspecting, i am using rest URL that has data, some how when try to fetch and get a request and getting this following error from the browser.


Access to fetch at '' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Failed to load resource: net::ERR_FAILED

What I have tried:

<pre>import React, { useState, useEffect } from 'react'
export default function Posts() {
  const [post, getPosts] = useState([])
  const API = '';
  const fetchPost = () => {
      .then((res) => res.json())
      .then((res) => {
  useEffect(() => {
  }, [])
  return (
      <h2>React Fetch Data with REST API Example</h2>
        {, i) => {
          return <li key={i}>{}</li>

import React from 'react'
import Posts from './components/Posts'
function App() {
  return (
    <div className="container">
      <Posts />
export default App;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900