DEV Community

Harish raj
Harish raj

Posted on

28/10/26 react (fetch)

#re

fetch(url).then(res-->resjson()
.then((data)=>data this is old method in js .

new method
NPM i asios in ---> cmd

asios.get (url)
then ((res=>res.data); --->it is use to fetch the api.

asios.get (url)
then ((res=>res.)=>console.log(res data.data.product))

           |
           |
           V
Enter fullscreen mode Exit fullscreen mode

dont change json manualy in react .
it will change automatically change.

mounting :
first the call the html file (app.jsx to main.jsx)

update:
using to set to give value.

unmounting:
to remove like if else .else using remove.

in axios method:
if you use usestate fetch data will be renddering because of usestate . but it fetching same value . then why should render because . the api data will state[],[] lot of arrays so it is rendering if you let i=10, j=10, is support it will not rendering . to resolve the render issue using useeffect (c)={.

Top comments (0)