Last active
March 7, 2019 15:13
-
-
Save khola/52874a17ba34d342841dd0b42c9730bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState, useEffect } from "react"; | |
import { API } from "aws-amplify"; | |
function useAPI(api, endpoint, settings, method = "get") { | |
const [data, setData] = useState(); | |
const [loading, setLoading] = useState(true); | |
async function callAPI() { | |
const response = await API[method](api, endpoint, settings); | |
setData(response); | |
setLoading(false); | |
} | |
useEffect(() => { | |
callAPI(); | |
}, []); | |
return [data, loading]; | |
} | |
export { useAPI }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment