在React中将数组传递给组件属性

Guy*_*Guy 15 javascript reactjs

如何将数组作为属性传递给组件.以下两点都没有实现我想要的.我想传递项目数组,在组件中操作它们并在render方法中输出.

<List columns=['one', 'two', 'three', 'four'] /> // unexpected token
<List columns="['one', 'two', 'three', 'four']" /> // passed through as string not array
Run Code Online (Sandbox Code Playgroud)

对于这种事情,是否有标准语法或最佳实践?

roj*_*oca 27

你需要使用{}js表达式:

<List columns={['one', 'two', 'three', 'four']} />
Run Code Online (Sandbox Code Playgroud)