ruby on rails - ReactJS with dynamic type objects -
i working on project convert of rails view layer reactjs. 1 of challenge have render list of dynamic type of objects (objects using sti).
for example, trying render bag of fruits, , each fruit has specific partial views in rails. in rails,
fruits.each |fruit| #fruit.type orange, apple, banana, etc. render 'fruits/' + fruit.type end
how do in reactjs? possible?
you can create object.
var things = { foo: foocomponent, ... };
and component that.
var key = 'foo'; var component = things[key]; return <component />
note variable must start uppercase letter if you're using jsx, otherwise assume mean html element <component></component>
.
or don't use jsx here.
react.createlement(things[key], null);