Skip to content

Instantly share code, notes, and snippets.

@dektaiimage
Created May 25, 2022 10:36
Show Gist options
  • Save dektaiimage/6e9a5fd6ef02ea87028ee97c0cf69ee1 to your computer and use it in GitHub Desktop.
Save dektaiimage/6e9a5fd6ef02ea87028ee97c0cf69ee1 to your computer and use it in GitHub Desktop.
Example React Custom Hooks
import React, { useState, useEffect } from 'react';
import axios from 'axios';
export default function useFetch(url){
const [data, setData] = useState([]);
useEffect(() => {
const fetchData = async () => {
const { data } = await axios.get(url)
setPosts(data);
}
fetchData();
},[url])
return{
data
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment