Best sample for relaying my responsive component?
Typically you should pass a data object to a component as a prop, even if it is a global variable. This allows you to test the component and also use it elsewhere without being bound to this global.
As Mike said, there is nothing wrong with using React.renderComponent to update it.
He also mentioned flux, but that's overkill for that. Simplest random emitter where you do something like .emit('change', newData)
and the component that listens to the change event tends to be better for simpler cases. See my answer to this question for an example of how this can be done.
source to share
I had the same problem and asked myself if I really needed to redo the component.
You can do this with this.forceUpdate()
, but this is not recommended. Since the React docs state :
You should try to avoid all uses of forceUpdate () and only read from this.props and this.state in render (). This makes your component "clean" and your application much simpler and more efficient.
So, I created a property data
like exists
and tested it:
// renderDeleteButton() is being called on render()
renderDeleteButton () {
if (!this.props.store.exists) {
return;
}
return(
<DeleteButton
...
deleteAction={this.delete} />
);
}
Whenever I delete / save, I switch exists
and the component will show or hide based on that. React handles this for me.
source to share