网站更新内容:请访问: https://bigdata.ministep.cn/

“useeffect hook try catch asunc await” Code Answer’s

useeffect async await
const getUsers = async () => {
 const users = await axios.get('https://randomuser.me/api/?page=1&results=10&nat=us');
 setUsers(users.data.results);
};

useEffect(() => {
 getUsers();
}, []);
async useEffect
 function OutsideUsageExample() {
  const [data, dataSet] = useState<any>(null)

  const fetchMyAPI = useCallback(async () => {
    let response = await fetch('api/data')
    response = await response.json()
    dataSet(response)
  }, [])

  useEffect(() => {
    fetchMyAPI()
  }, [fetchMyAPI])

  return (
    <div>
      <div>data: {JSON.stringify(data)}</div>
      <div>
        <button onClick={fetchMyAPI}>manual fetch</button>
      </div>
    </div>
  )
}

 

[useeffect hook try catch asunc await Code Example](https://www.codegrepper.com/code-examples/javascript/useeffect+hook+try+catch+asunc+await)

 

 
 

 

 
 
posted @ 2021-12-13 22:58  ministep88  阅读(39)  评论(0编辑  收藏  举报
网站更新内容:请访问:https://bigdata.ministep.cn/