Hi there.
i’m trying to set one of my states after calling a function but i keep getting an error when i try to do so. does anyone know what’s the problem here?
import React , {useState} from ‘react’
function App(){
const [name , setName] = useState('')
const [isLoading , setIsLoading] = useState(false)
function fetchData(){
setIsLoading(true)
const url = 'https://swapi.dev/api/people/1'
fetch(url)
.then(response => response.json())
.then(data => {
setName(data.name)
})
}
fetchData()
return(
<div>
{name}
</div>
)
}
export default App
here when i’m trying to do “setIsLoading(true)” when the function starts i get an error but otherwise it works fine(i’m trying to add a loading message to the screen).