【问题标题】:Warning: setState(...) ..., endless loop [duplicate]警告:setState(...) ...,无限循环[重复]
【发布时间】:2018-05-07 03:23:47
【问题描述】:

进入页面时出现此错误

警告:setState(...):在现有状态转换期间无法更新(例如在render 或其他组件的构造函数中)。渲染方法应该是 props 和 state 的纯函数;构造函数副作用是一种反模式,但可以移至componentWillMount

在 form.js 中

render() {
    return (
    ...
    <Row className={css(stylesClient.adm_search)}>
        <Col span={3} style={{fontSize: '24px'}}>Приёмы</Col>
        <Col span={3} offset={7}>Период: с</Col>
        <Col span={4}>
            <Datetime
                className="date_time"
                dateFormat="DD.MM.YYYY"
                timeFormat={false}
                locale="ru"
                onChange={(e)=>this.setState({dateStart: e.target.value})}/>
        </Col>
        <Col span={1}>по</Col>
        <Col span={4}>
            <Datetime
                className="date_time"
                dateFormat="DD.MM.YYYY"
                timeFormat={false}
                locale="ru"
                onChange={(e)=>this.setState({dateEnd: e.target.value})}/>
        </Col>
        <Col span={2}>
            <Button
                className={css(stylesClient.set_button)}
                onClick={this.props.receptions_filter(this.state.dateStart, this.state.dateEnd)}>
                <img style={{marginLeft: '-10px'}} src={arrowWhite}/>
            </Button>
        </Col>
    </Row>
    ...
    )
}

我需要按两个日期过滤表格,但死循环,我最近开始了解Web技术。

对不起我的英语不好

【问题讨论】:

    标签: reactjs redux


    【解决方案1】:

    onClick 在每次渲染时都会被触发。

    改成:

    onClick={() =&gt; this.props.receptions_filter(...)}

    【讨论】:

      猜你喜欢
      • 2016-10-22
      • 1970-01-01
      • 1970-01-01
      • 2020-09-13
      • 2021-01-08
      • 1970-01-01
      • 2021-02-13
      • 1970-01-01
      • 2020-06-06
      相关资源
      最近更新 更多