π Intro
This blog will touch the base of how to interact with server in React, how to use the useEffect
hook to fetch data from server and more related concepts like fetch
, promises
, event loop
.
π‘ New concepts
- Fetch method:
The fetch() method starts the process of fetching a resource from the network, returning a promise which is fulfilled once the response is available. More details - Promise:
The promise object represents the eventual completion (or failure) of an asynchronous operation and its resulting value. More details - Event loop:
The event loop is a programming construct or design pattern that waits for and dispatches events or messages in a program. More details - useEffect hook:
TheuseEffect
is a React Hook that lets your synchronize a component with an external system. More details
π Lessons learned
The {}
you see when accessing base url of a server
During the course weβre using JSON server. When you access the base url of a server, you will see a {}
. This is because the server is returning a JSON object. The {}
is the representation of the JSON object in the browser. This is not an eeror or problem, it is just how JSON Server handles requests to the root URL.