Chartjs-Getting Error regarding :Cannot read property 'length' of undefined

1👍

useState return an array, not an object

From your code

const Charts = () => {
  // const { setDailyData, dailyData } = useState([]);
  const [dailyData, setDailyData] = useState([]) // <-- change to this

  useEffect(() => {
    const fetchAPI = async () => {
      setDailyData(await fetchDailyData());
    };
    console.log(dailyData);

    fetchAPI();
  }, []);

Leave a comment