passings array as props in reactjs

The curly braces only need to be used within JSX elements. Like this:

<MyComponent somProp={['something']} />

In the case above, the {} is the way of saying: “Evaluate the expression that I passed within and pass it as a prop”. Within the {} you can pass any valid JavaScript object or expression. Note that if you pass a string, and specifically for strings, you don’t need the curly braces… like <MyComponent somProp="something" />.

The above code is the equivalent of this:

var myArray = ['something'];
<MyComponent somProp={myArray} />

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)