can't find variable :useState

Viewed 14211

So I get this error after I fetched data and tried to assign it to my const. I'm using hooks for the first time and I don't know what I did wrong. here is my code:

export default function MedProfilScreen({route}){
    //const {id,name,specialite,work}=route.params;
    const [data,setData]=useState([])
    useEffect(()=>{
      fetch('http:......)
    
    .then((response) => response.json())
    .then((res) => {
      setData(data.res);
    console.log(res)
   })
    .done();
    });

And this is what the console.log shows:

Array [
  Object {
    "code": "12459552",
    "id": 7,
    "name": "Dr xavier vilan",
    "speciality": "Cardio",
  },
  Object {
    "education": Array [
      Object {
        "date_debut": "2020-02-07",
        "date_end": "2020-02-06",
        "diplome": "asmaa",
        "school": "asmaa",
        "city": "vullez",
      },
      ]}
]
2 Answers

Add

import {useState} from "react";

You can import useState from React, or use React.useState (if you imported 'react' as React). Also, you must provide the setData to useEffect, or it will render a warning.

useEffect(() => {your function}, [setData])
Related