Skip to content

Instantly share code, notes, and snippets.

@mahmoodchowdhury
Last active May 9, 2026 01:51
Show Gist options
  • Select an option

  • Save mahmoodchowdhury/cc2e341fb0de390c2768d752823f26e1 to your computer and use it in GitHub Desktop.

Select an option

Save mahmoodchowdhury/cc2e341fb0de390c2768d752823f26e1 to your computer and use it in GitHub Desktop.
Fetch Data using Fetch API or Axios in React Application
import { useEffect, useState } from 'react';
function Posts() {
const [posts, setPosts] = useState([]);
useEffect(() => {
fetch('https://your-site.com/wp-json/wp/v2/posts')
.then(res => res.json())
.then(data => setPosts(data));
}, []);
return (
<ul>
{posts.map(post => (
<li key={post.id}>{post.title.rendered}</li>
))}
</ul>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment