728x90 반응형 async2 Async Functions in Javascript import React, { useState, useEffect } from 'react'; function DataFetcher() { const [data, setData] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { async function fetchData() { try { const data = await fetchData('https://api.example.com/data'); setData(data); setLoading(false); } catch (error) { setError(error); setLoadin.. 2024. 4. 1. Async/Await 비동기 처리를 할 수 있는 방법 Callback Promise Async/Await Async aysnc 함수의 리턴값은 promise 이다. function myFunc(){ return 'func'; } async function myAsync(){ return 'async'; } console.log(myFunc()); console.log(myAsync()); 결과는 func Promise {: "async"} async function myAsync(){ return 'async'; } myAsync().them((result) => { console.log(result); }); 결과는 async 즉, promise는 비동기 연산을 다루되, 비동기 연산이 끝나면 resolve하고 resolve.. 2019. 5. 4. 이전 1 다음 728x90 반응형