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

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -