Fetch Method
The fetch method in JS is used to request to the server and load the information in the webpages. The request can be of any APIs that return the data of the format #json or #xml . This method returns a promise. Have a look example. Lets move on to next method
Async-Await
It is the preferred way of fetching the data from an API as it enables us to remove our .then() callbacks and return asynchronously resolved data. In the async block, we can use Await function to wait for the promise. Lets move on to next method
Axios Library
With Axios, we can easily send asynchronous HTTP requests to REST APIs & perform create, read, update and delete operations. Axios can be imported in plain JavaScript or with any library accordingly. Lets move on to next method
Custom Hooks
It is basically a React component whose name will start with "use" like useFetch. It can use one or more React hooks inside them. Lets move on to next method
Using in the component
Import the useFetch hook and pass the URL of the API endpoint from where you want to fetch data. Now just like any React hook we can directly use our custom hook to fetch the data. Lets move on to next method
React Query Library
With this we can achieve a lot more than just fetching data. It provides support for caching and prefetching, which impacts the overall user experience by preventing irregularities and ensuring our app feels faster.
Like, Share and Subscribe #DevTools99 for more useful videos, tools info and #tutorials . Thank you!