Skip to content

Instantly share code, notes, and snippets.

View hamza4600's full-sized avatar
:octocat:
I may be slow to respond.

Hamza Khan hamza4600

:octocat:
I may be slow to respond.
View GitHub Profile
@hamza4600
hamza4600 / gist:5fc3a05a6bc0d71a6b2bfa50f9579974
Last active November 24, 2022 19:24
Custom Hook to get Data from Api and Show Response in React
import { useState } from "react";
function useData(url) {
const [data, setData] = useState([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState(null);
const [localData, setLocalData] = useState(
JSON.parse(localStorage.getItem("data")) || []
);