Please someone should help me ...ypeError: Cannot read properties of undefined (reading 'length')

  useEffect(() => {
        // declare the async data fetching function
        const fetchData = async () => {
          // get the data from the api
          const params = {ethAddress: Address};
          const data = await'getFollowers', params);
         const userdata= await'getUser', params);
          // convert the data to json
          //const json = await data.json();
          // set state with the result
            for (let i = 0; i < data.followers.length; i++) {
             // dict[[i].id]=1;
               setfollowers_id(prevState => ({
        // call the function
          // make sure to catch any error
      }, [])

You can try to check the value of that variable.

Please help me โ€ฆI am new to this โ€ฆthank you

You can try to add some debugging with console.log

Please can you show me an example

An example: console.log(variable_name)

try to do as @cryptokid says and console.log(data.followers) it must be undefined

Iโ€™m not very sure how you structure your state, but if you donโ€™t initialize anything in useState, then I also suggest you to initialize it with an empty array

1 Like