How to Use Async Await with React's useEffect Hook
https://harrisonstandeffer.com/async-await-in-react-use-effect-hooks/
比如实例:
useEffect(() => {
axios.get('/api/users')
.then(response => {
setUsers(response.data)
})
}, [])
useEffect(() => {
const fetchUsers = async () => {
const usersObject = await axios.get('/api/users')
setUsers(usersObject)
}
fetchData()
}, [])