skip to Main Content

Reactjs – React: Confusion about how useEffect hook works

So here's the code I'm confused about: import React from "react" export default function App() { const [starWarsData, setStarWarsData] = React.useState({}) console.log(starWarsData) React.useEffect(function() { fetch("https://swapi.dev/api/people/1") .then(res => res.json()) .then(data => setStarWarsData(data)) }, [starWarsData]) return ( <div> <pre>{JSON.stringify(starWarsData, null, 2)}</pre> </div>…

VIEW QUESTION
Back To Top
Search