Whenever i visit a page it should automatically fetch the api
import React from 'react'
const comp = () => {
fetch("api url").then((res)=>console.log(res))
return (
<div>comp</div>
)
}
export default comp
>Solution :
It is very simple using react hook use effect please learn basics of useffect hook on react docs or any youtube tutorial and as for the answer
import React, { useEffect } from 'react'
const comp = () => {
useEffect(() => {
fetch("api url").then((res)=>console.log(res))
}, [])
return (
<div>comp</div>
)
}
export default comp
here empty dependency means every time page loads only once