Guy
Guy

Reputation: 11305

Passing array to component property in React

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?

Upvotes: 15

Views: 12287

Answers (1)

rojoca
rojoca

Reputation: 11190

You need to use {} around js expressions:

<List columns={['one', 'two', 'three', 'four']} />

Upvotes: 27

Related Questions