We have been experiencing some problems in using react now but it kinda boils to one part of how we have been using react.
How should we have been showing/hiding child components?
This is how we have coded it (this are only snippets of our components)...
_click: function() {
if ($('#add-here').is(':empty'))
React.render(<Child />, $('#add-here')[0]);
else
React.unmountComponentAtNode($('#add-here')[0]);
},
render: function() {
return(
<div>
<div onClick={this._click}>Parent - click me to add child</div>
<div id="add-here"></div>
</div>
)
}
and lately I've been reading examples like it should've been somewhere along this lines:
getInitialState: function () {
return { showChild: false };
},
_click: function() {
this.setState({showChild: !this.state.showChild});
},
render: function() {
return(
<div>
<div onClick={this._click}>Parent - click me to add child</div>
{this.state.showChild ? <Child /> : null}
</div>
)
}
Should I have been using that React.render()? It seems to stop various things like shouldComponentUpdate
to cascade to child and things like e.stopPropagation
...