Cannot read properties of undefined (reading 'forEach') inside useEffect

99 Views Asked by At

I try to change render when there is a change with useEffect and I have this error "Cannot read properties of undefined (reading 'forEach')". when I log the console print the array and its values.

  const listMemo = useMemo(() => ({ list }), [list]);
  useEffect(() => {
    console.log(list)   //Print the array 
    console.log(listMemo)   //Print the array
    listMemo.list.array.forEach((element, i) => {
      //********************************
      //*************************************** */
      }
    });
  }, [listMemo]);

enter image description here

1

There are 1 best solutions below

0
On BEST ANSWER

listMemo.list.forEach(

NOT listMemo.list.array.forEach( - remove array and one of dots.