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?
CodePudding user response:
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 ).