Skip to content

Instantly share code, notes, and snippets.

@Chryus
Created March 13, 2020 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Chryus/bbec383d11f38ef61e74aec28ca45269 to your computer and use it in GitHub Desktop.
Save Chryus/bbec383d11f38ef61e74aec28ca45269 to your computer and use it in GitHub Desktop.
// fetchData.js
import { useState, useEffect } from "react";
export default function fetchData(url) {
const [data, setData] = useState([]);
useEffect(() => {
fetch(url)
.then(response => response.json())
.then(data => setData(data));
}, []);
return data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment