Can I create a new component on a onClick-event in reactjs.
I've tried this:
My component where the click event occurs:
...
<li onClick={this.edit.bind(this)}><span className="glyphicon glyphicon-pencil"></span> Edit entry</li>
...
This is the edit method:
edit(event) {
return <CreateFreightEntryModal key={"freightEditModal" + this.state.freight.ID} openOnStartup="true" modalId={"freightEditModal" + this.state.freight.ID} />
}
No error is thrown, but the component is not being created. Doing I something wrong or is this not really recommended?
CreateFreightEntryModalcomponent to be rendered instead of whatever is normally there.setStateand update that with true, use that variable to render the Component, Check the Conditional Rendering part of Doc{ flag ? component : null}in render