K
K
KnightForce2017-05-10 18:48:39
React
KnightForce, 2017-05-10 18:48:39

If the parent has shouldComponentUpdate return fasle, will nested elements be updated?

class someClass1 extends Component {
  constructor(props) {
    super(props);
    this.props = props;
  }

        shouldComponentUpdate() {
                return false;
        }
  render() {
    return <div></div>
  	}
}

class someClass1 extends Component {
  constructor(props) {
    super(props);
    this.props = props;
  }
  render() {
    return <span></span>
  	}
}

<someClass1>
    <someClass2/>
</someClass1>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita Gushchin, 2017-05-10
@KnightForce

If shouldComponentUpdate returns false, the render method of the current component will not be called. Accordingly, child components will also not start rendering themselves. But it may happen (for example - on a timer) that you call setState in the child component - then it will be updated (regardless of the parent)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question