Last active
November 9, 2019 23:38
-
-
Save oquirozm/97338538c7b07b327dc6f322f37de27b 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 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