Reputation: 85765
I am wondering what is best practice. Should you let all components render or should you stop them from rendering? Say I have a delete modal that only gets shown on a click.
Should I put in my render of my modal
render() {
// if something return false to stop rendering
return ( )
}
Upvotes: 1
Views: 4746
Reputation: 2851
Design your DeleteModal
component so that in its render()
method it renders the required UI, always. Then in the parent component, the one that uses the dialog, you conditionally show/hide it:
render() {
return (
<div>
some content here
...
{showDeleteModal ? <DeleteModal /> : null}
</div>
);
}
Upvotes: 5