Ad

Passing Array To Component Property In React

- 1 answer

How can I pass an array to a component as a property. Neither of the following achieve what I am looking for. I want to pass the array of items through, manipulate them in the component and output in the render method.

<List columns=['one', 'two', 'three', 'four'] /> // unexpected token
<List columns="['one', 'two', 'three', 'four']" /> // passed through as string not array

Is there a standard syntax or best practice for this kind of thing?

Ad

Answer

You need to use {} around js expressions:

<List columns={['one', 'two', 'three', 'four']} />
Ad
source: stackoverflow.com
Ad