Quote:localhost/:1 Access to fetch at 'https://fe-assignment.vaimo.net/posts' 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. fe-assignment.vaimo.net/posts:1 Failed to load resource: net::ERR_FAILED
<pre>import React, { useState, useEffect } from 'react' export default function Posts() { const [post, getPosts] = useState([]) const API = 'https://fe-assignment.vaimo.net/posts'; const fetchPost = () => { fetch(API) .then((res) => res.json()) .then((res) => { console.log(res) getPosts(res) }) } useEffect(() => { fetchPost() }, []) return ( <> <h2>React Fetch Data with REST API Example</h2> <ul> {post.map((item, i) => { return <li key={i}>{item.name}</li> })} </ul> </> ) }
import React from 'react' import Posts from './components/Posts' function App() { return ( <div className="container"> <Posts /> </div> ) } export default App;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)