Last active
May 9, 2026 01:51
-
-
Save mahmoodchowdhury/cc2e341fb0de390c2768d752823f26e1 to your computer and use it in GitHub Desktop.
Fetch Data using Fetch API or Axios in React Application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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