Download Movix/src/hooks/useFetch.jsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 720 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/f5071caa249115f3b590492f1c8eb471e02aae4b/Movix/src/hooks/useFetch.jsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@f5071caa249115f3b590492f1c8eb471e02aae4b/Movix/src/hooks/useFetch.jsx
-
curl -L -o useFetch.jsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/f5071caa249115f3b590492f1c8eb471e02aae4b/Movix/src/hooks/useFetch.jsx
720 Bytes
| import { useEffect, useState } from "react"; | |
| import { fetchDataFromApi } from "../utils/api"; | |
| const useFetch = (url) => { | |
| const [data, setData] = useState(null); | |
| const [loading, setLoading] = useState(null); | |
| const [error, setError] = useState(null); | |
| useEffect(() => { | |
| setLoading("loading..."); | |
| setData(null); | |
| setError(null); | |
| fetchDataFromApi(url) | |
| .then((res) => { | |
| setLoading(false); | |
| setData(res); | |
| }) | |
| .catch((err) => { | |
| setLoading(false); | |
| setError("Something went wrong!"); | |
| }); | |
| }, [url]); | |
| return { data, loading, error }; | |
| }; | |
| export default useFetch; | |