Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Uncaught TypeError: Cannot read properties of undefined (reading '0') at line 13:1

while working on code ran into some errors on line 13 when the value is undefined and is reading as 0 please how can I solve this

the error message

homepage.js:13 Uncaught TypeError: Cannot read properties of undefined (reading ‘0’)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  const dispatch = useDispatch();
  const danceClass = useSelector((state) => state.class);
  const { classes } = danceClass;

  const [dance, setDance] = useState(
    classes[0] ? classes[0].slice(0, 3) : [],
  );

>Solution :

Because the classes is undefined. You should check like

classes ? classes[0]?.slice(0,3) : []
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading