Assessment needed in solving a setState problem(React)

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).

Hello @Ali_Servat

sorry ali looks like no one has any experience in the react in the community to help you

@cchqy can you help him here :slight_smile:

Hi @justsomeone

Sorry I cannot provide any further help, I am also a beginner.

1 Like

Hi @cchqy

it’s ok do not be sorry and have a nice day :slight_smile: