0

我在子组件中有下面的 JSX。

<td>
  <div>
    {this.props.image_element} 
  </div> 
</td>

function在父组件中如下所示

image_element= (image_name) => {        
        if(image_name) {
            this.update_photostatus('image');
        }
        else {
            console.log('hello');
            this.update_photostatus('input');
        }
   }

update_photostatus = value => {
        this.setState({photostatus: value});
    }

我得到的输出console如下

在此处输入图像描述

在此处输入图像描述

4

1 回答 1

0

Do not call setState within componentWillUpdate or componentDidUpdate or render method, unless you have conditionals that restrict that change (even then be careful). When you setState inside one of these, you are likely to get the Maximum update depth exceeded message back.

于 2018-07-31T16:35:17.797 回答