infinite Render in React

后端 未结 3 1971
隐瞒了意图╮
隐瞒了意图╮ 2020-12-20 22:17

I am having problem figuring out why my application is doing endless render.

Inside, My stateful component, I am calling a redux action in componentDidMount method (

3条回答
  •  时光取名叫无心
    2020-12-20 22:41

    It seems Jacob in the above comment has managed to make the component render only twice.

    This will definitely cause double initial render (and would cause an infinite render if it wasn't a PureComponent):

    componentDidUpdate() {
        var updateCoinData;
    
        if (!updateCoinData) { // <- this is always true
            updateCoinData = [...this.props.cryptoLoaded];
            this.setState({updateCoinData: true}); // <- this will trigger a re render since `this.state.updateCoinData` is not initially true
        }
        ...
    }
    

    Link to the issue in your repository

提交回复
热议问题