score:0

Accepted answer
const LineChart = () =>{
    const [chartData,setChartData]= useState({});
    const [myresponse, setmyresponse] =useState([]);
  const isMountedRef = useRef(null);
    useEffect(() =>{
    isMountedRef.current = true;
        let countcluster = [];
        let listregion = [];
        axios.get("http://localhost:5001/inventory/clusterscount").
        then(res=>{
           if(isMountedRef.current){
   const myresponse= res.data;
            setmyresponse(myresponse)
            console.log(myresponse);
         for (const dataobj of myresponse){
             countcluster.push(parseInt(dataobj.clusterscount));
             listregion.push(dataobj.region);
         }
         setChartData({
            labels: listregion,
            datasets: [
              {
                label: "level of thiccness",
                data: countcluster,
                backgroundColor: ["rgba(75, 192, 192, 0.6)"],
                borderWidth: 4
              }
            ]
          });
     
        }
        
         
        })
    .catch(err=>{
        console.log(err);
    });
    return () => isMountedRef.current = false;
    },[])


Related Query

More Query from same tag