Commerce.js cart.line_items is not returning as an array at the start and is giving me an error

272 Views Asked by At

I am trying to find whether my cart is empty by using const isEmpty = !cart.line_items.length;, but it is returning Cannot read property length of undefined. So i console.logged whether cart.line_items is an array and it ends up returning false, true, true. So for some reason it isnt recognized as an array at the start. How would I fix this?

1

There are 1 best solutions below

0
Arxci On BEST ANSWER

Adding this catch if(!cart.line_items) return 'Loading...' seemed to solve the problem