Hi guys, glad to see you again. Today we gonna talk about API and method fetch. Our project will work with real data from Server!
The most popular API server for learning – is Jsonplaceholder. Lets open this site. Scroll down:
Resources
/posts 100 posts
I`m pushing this button and we here we have a page with data. Ok. I`m grabbing this link and typing code. I am jumping to App, getting rid of this garbage… Now I am creating a new variable. This is async function- because if we work with API we should use async requests…
Method json()
It returns a promise which resolves with the result of parsing the body text as JSON.
And finally we unloading our data to useState. We are creating use State and defining types. I`m grabbing one object from this page
…and doing our work.
{
“userId“: 1,
“id“: 1,
“title“: “sunt a
7 views
708
200
1 year ago 00:20:34 1
Пишем парсер на JavaScript | QA
2 years ago 00:05:43 3
TypeScript + React #10 Типизация асинхронных функций (Typing of Fetch with Async & Await)