coffeescript - ReactJS dynamically call custom class -
i trying setup way create form objects dynamically json values. essentially, have in json form object type , properties. pass type forminput class calls custom class containing actual form object. problem right when pass in custom class name "textinput" (this.props.formelementtype) react creates element called 'textinput' instead of calling class. doesn't appear passing in string, wants classname. essentially,...
textinput = react.createclass({...}) ... formitem = react.createelement(<textinputpassedasastring>, {...}) i not sure if can call custom class way or not, passing string. need implementation or better idea relatively new react.
below relevant code starting children ending final render block. please excuse pseudo coffeescript.
textinput
textinput = react.createclass handlechange: (event)-> this.setstate value: event.target.value render: -> react.createelement('label', { value: this.props.formelementlabel }) react.createelement('input', { id: this.props.formelementid, type: 'text' }) module.exports = textinput formelement
formelement = react.createclass render: -> r.div(null, react.createelement(this.props.formelementtype, { formelementid: this.props.formelementid, formelementlabel: this.props.formelementlabel }) module.exports = formelement the initial call/final render
react.createelement(formelement, { formelementtype: 'textinput', formelementid: 'firstformelement', formelementlabel: 'first text input' })
well, best way, easiest reason about, etc. require textinput in module that's doing final render. create there, passing in other props it, , pass created component formelement rather passing string representation of component.
one way more dynamically have have module exports each dynamic component property/method on export. like:
module.exports = { textinput: ... } then when you're rendering pass in this:
myimports[json.formelementtype]
Comments
Post a Comment