const [data, setData] = useState([]); //Fetch data from a local json file. const getData = () => { fetch("data.json", { headers: { "Content-Type": "application/json", Accept: "application/json", }, }) .then(function (response) { console.log(response); return response.json(); }) .then(function (myJson) { console.log(myJson); setData(myJson); }); }; useEffect(() => { getData(); }, []);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter