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

React callback return not iterable instance

I’m using ant-desing(v3.26.14) List component in React. Normally if I try to pass plain array to ‘dataSource’ property then everything is fine. But when I try to pass array via callback it’s given error.

<List dataSource={someArray} /> //is fine
<List dataSource={() => someArray} /> //getting error

Error: ‘TypeError: Invalid attempt to spread non-iterable instance.
In order to be iterable, non-array objects must have a Symbol.iterator method.’

I wonder is this normal behaviour of javascript or some library issue and why that’s happening, isn’t this the same thing?

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

>Solution :

I think it’s because the List component is expecting the array so it can use the spread, but you are giving it a callback function. It doesn’t expect a callback function but an iterator ( array in this case ).

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