Skip to content

Instantly share code, notes, and snippets.

@Chryus
Created March 12, 2020 15:11
Show Gist options
  • Save Chryus/555ab59560b4ddf4f513787dd295c089 to your computer and use it in GitHub Desktop.
Save Chryus/555ab59560b4ddf4f513787dd295c089 to your computer and use it in GitHub Desktop.
// dataFetcher.js
import { useState, useEffect } from "react";
export default function dataFetcher(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