Created
September 17, 2021 13:22
-
-
Save NeoYo/1404cdd139ef6ce0fe43c60e11583f3e to your computer and use it in GitHub Desktop.
How to Use React useEffect - Request data
Raw
comment-list.jsx
This file contains 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
Show hidden characters
function CommentsList() { | |
const [comments, setComments] = useState([]); | |
useEffect(() => { | |
// Fetch Comments | |
fetchComments().then(response => { | |
// ... | |
setComments(response.data); | |
}); | |
}, []); | |
return ( | |
<ul> | |
{ comments.map(comment => <li>{comments}</li>) } | |
</ul> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment