Skip to content

Instantly share code, notes, and snippets.

@oquirozm
Last active November 9, 2019 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oquirozm/97338538c7b07b327dc6f322f37de27b to your computer and use it in GitHub Desktop.
Save oquirozm/97338538c7b07b327dc6f322f37de27b to your computer and use it in GitHub Desktop.
import axios from 'axios';
import { useState, useEffect } from 'react';
function useCharacterForm() {
const [loading, setLoading] = useState(false);
const [characters, setCharacters] = useState(null);
const [error, setError] = useState(null);
useEffect(() => {
setLoading(true);
axios
.get('https://the-one-api.herokuapp.com/v1/character', {
headers: { Authorization: `Bearer ${process.env.REACT_APP_API_TOKEN}` }
})
.then(res => {
setCharacters(res.data.docs);
setLoading(false);
})
.catch(err => {
setError(true);
setLoading(false);
});
}, []);
return {
characters,
loading,
error
};
}
export default useCharacterForm;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment