coffeescript - Dynamically generate React component names -
i'm having trouble finding solution this. how can convert code below more dynamic , succinct?
onecomponent = require ('./onecomponent') twocomponent = require ('./twocomponent') threecomponent = require ('./threecomponent') example = react.createclass render: -> filter = @props.filterstate if filter 'something' tablecmpt = <div> <onecomponent tasks={@props.tasks} /> </div> if filter 'somethingelse' tablecmpt = <div> <twocomponent tasks={@props.tasks} /> </div> ##... etc return tablecmpt
i've done this.
var components = { 'something': require('./component'), 'somethingelese': require('./component2') }; example = react.createclass({ render: function() { var component = components[this.props.filter]; return <div><component tasks={this.props.tasks}/></div>; } });
Comments
Post a Comment