Skip to content

Instantly share code, notes, and snippets.

@khola khola/useAPI.js
Last active Mar 7, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.