D
D
danilr2019-07-30 05:43:53
React
danilr, 2019-07-30 05:43:53

Why does it loop and how to avoid it?

componentWillUpdate() {
        console.log('componentWillUpdate');
        const {pageScroll} = this.props;
        this.setState({
            availableHeight: pageScroll ? document.querySelector('#page').clientHeight : findDOMNode(this) ? findDOMNode(this).clientHeight : 0
        });
    }

Tell me why it goes into an infinite loop and how to avoid it?
The problem is that I need availableHeight to be the height of the component. Initially called setState in WillMount, but for some reason it considered the height with a lagging of one step.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
real2210, 2019-07-30
@danilr

Because you set state -> component re-renders -> will update fires -> you set state -> component re-renders...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question