You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Custom Hook to fetch jobs from the APIimport{useState,useEffect}from"react";import{SEARCH_API}from"../lib/constants";import{JOBITEM}from"../lib/types";typeDataProps={public: boolean;sorted: boolean;jobItems: JOBITEM[];};exportfunctionuseFetchJobs(search: string): [JOBITEM[],boolean]{const[jobs,setJobs]=useState<JOBITEM[]>([]);const[isLoading,setIsLoading]=useState(false);useEffect(()=>{if(!search||search.length<3)return;constcontroller=newAbortController();constsignal=controller.signal;constfetchData=async()=>{try{setIsLoading(true);constresponse=awaitfetch(SEARCH_API+search,{ signal });constdata: DataProps=awaitresponse.json();setJobs(data.jobItems);}catch(e){console.error(e);}finally{setIsLoading(false);}};fetchData();return()=>{controller.abort();};},[search]);return[jobs,isLoading];}
The text was updated successfully, but these errors were encountered:
Project: rmtdev
Video: 132
Instead of using
as const
a far safer alternative is to simply define the return value for the custom hookFull Code
The text was updated successfully, but these errors were encountered: