javascript describe the process of a fetch] code example
Example 1: get data from api in javascript
const GetData = [];
useEffect(() => {
fetch(API_URL)
.then((res) => res.json())
.then((data) => {
GetModesData.push(...data);
setDataState(GetData.map((d) => d.modeName));
});
}, []);
Example 2: .fetch method
fetch('http://example.com/data.json')
.then(data => data);
.catch(err => console.log(err));