Search
 
SCRIPT & CODE EXAMPLE
 

CSS

customHook-axios

const useFetch = (url, initialValue) => {
  const [data, setData] = useState(initialValue);
  const [loading, setLoading] = useState(true);
  useEffect(() => {
    const fetchData = async function () {
      try {
        setLoading(true);
        const response = await axios.get(url);
        if (response.status === 200) {
          setData(response.data);
        }
      } catch (error) {
        throw error;
      } finally {
        setLoading(false);
      }
    };
    fetchData();
  }, [url]);
  return { loading, data };
};
function EffectsDemoCustomHook() {
  const { loading, data } = useFetch(
    "https://jsonplaceholder.typicode.com/posts/"
  );
  return (
    <div className="App">
      {loading && <div className="loader" />}
      {data?.length > 0 &&
        data.map((blog) => <p key={blog.id}>{blog.title}</p>)}
    </div>
  );
}
Comment

PREVIOUS NEXT
Code Example
Css :: laravel public css not found 
Css :: sass dummy folder site download 
Css :: low opacity whit out toching child nods 
Css :: edge ontouchmove does not work correctly 
Css :: overwrite theme css in parent css 
Css :: bright btn background with white text 
Css :: css selector 
Css :: How do you display a border like this: 
Css :: how to highlight text in css 
Css :: tailwind css 
Css :: switch css with text 
Css :: tailwindcss top 
Css :: text width tailwindcss 
Typescript :: How to ignore an error in typescript 
Typescript :: dev/storage/logs" and its not buildable: Permission denied 
Typescript :: install typescript 
Typescript :: Do not use "// @ts-ignore" comments because they suppress compilation errors 
Typescript :: unity find all objects with script 
Typescript :: solidity license 
Typescript :: check typescript version 
Typescript :: download brackets code editor for ubuntu linux 
Typescript :: typescript singleton 
Typescript :: serenity.is disable row in grid 
Typescript :: how to call two method connected 
Typescript :: battle cats challenge battle 
Typescript :: key value pairs typescript 
Typescript :: sts getting slow while pressing control key 
Typescript :: track changes of input in angular 
Typescript :: iframe angular src detect changes 
Typescript :: nodejs jszip create zip file as buffer 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =