React.js passes the key-value pairs of an object as props

I often find myself doing something like this in my jsx:

myObject= {key1 : 'value1', key2 : 'value2'};
var reactElement = <MyReactElement key1={myObject.key1} key2={myObject.key2}/>;

Is there any infrastructure available that allows me to pass all the key pairs of values ​​in my object as bearings on an element? I know that I can walk through the entire object, but it does not feel as elegant as possible, especially if this is the only thing that I go through, since then I need to turn to this.props.myObject.key1.

+4
source share
1 answer

With React 0.12 and the latest version of jsx, you can use the spread operator.

<MyReactElement foo={bar} {...myObject} />
+12
source

All Articles