chobo2
chobo2

Reputation: 85765

Stop Render of Reactjs Component?

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

Answers (1)

m1kael
m1kael

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

Related Questions