Skip to content

Instantly share code, notes, and snippets.

@NeoYo
Created September 17, 2021 13:22
Show Gist options
  • Save NeoYo/1404cdd139ef6ce0fe43c60e11583f3e to your computer and use it in GitHub Desktop.
Save NeoYo/1404cdd139ef6ce0fe43c60e11583f3e to your computer and use it in GitHub Desktop.
How to Use React useEffect - Request data
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