below is the custom hook. I am trying to use context inside it. It throws the error “Invalid hook call. Hooks can only be called inside of the body of a function component”
export const useFetch = async () => {
const { city, setFetchError } = useContext(appcontext);
try{
const API_KEY = process.env.REACT_APP_WEATHER_API_KEY;
const currentResponse = await fetch(`https://api.weatherapi.com/v1/current.json?key=${API_KEY}&q=${city}`);;
if(currentResponse.ok){
const currentData = await currentResponse.json();
return currentData;
}
throw new Error('error fetching weather details')
}
catch(err){
setFetchError(true);
return null;
}
}
can someone explain in simple list which i have to check for custom hooks. like start with use and name should start with caps. stuff like that in simple ordered list.
New contributor
Ajith is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.