S
S
Stepan2015-12-27 21:59:33
JavaScript
Stepan, 2015-12-27 21:59:33

How to stop Render when new props are received?

Can't figure out componentWillReceiveProps still renders.
And I need to catch the condition so as not to call render

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Ostap Chervak, 2015-12-28
@xoma2

You need to use the method
of i.e. your case

shouldComponentUpdate(nextProps, nextState) {
    if (this.props.a != nextProps.a) {
        return false
    } else {
        return true
    }
}

or shorter
shouldComponentUpdate(nextProps) {
    return this.props.a !== nextProps.a;
}

by default in all React.Components shouldComponentUpdate returns true.
More details: https://facebook.github.io/react/docs/component-sp...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question