Im new in react, and i want to assign an array of objects to a React.FC state. My api logic looks like this:
class LandApi {
async getLands(): Promise<Land[]> {
const response = await fetch('http://localhost:8080/api/lands', {
method: 'GET',
headers: { 'Content-Type': 'application/json' }
});
return response.json();
}
}
And i have this functional component:
const MapLands: React.FC = () =>
{
let [state, setState] = useState([])
useEffect(() => {
LandApi.getLands().then((data) => {
setState({
landList: data //the problem is here
})
})
})
return (
<div>
{
//Map logic here
}
</div>
)
}
How can I 'put' that Land[] array in the functional components state, so i can map it later?
I'm pretty new to web programing as you can probably tell.
With sincere thanks,
Samuel