鍍金池/ 問答/Linux  HTML/ react表單里setstate后打開彈窗獲取不到數(shù)據(jù)

react表單里setstate后打開彈窗獲取不到數(shù)據(jù)

// 點(diǎn)擊彈窗
  handleShowConfig = obj => {
    const { firstWeight } = obj;
    this.setState({
      sendFee: {
        firstWeight,
      },
      visible: true,
    });
  }
const { sendFee } = this.state;
<Dialog
          visible={this.state.visible}
        >
          <Form>
            <Row>
              <Col>
                <FormItem
                  label="首重量:"
                >
                  <Input
                    {...init('firstWeight', {
                      initValue: sendFee.firstWeight,
                    })}
                  />
                </FormItem>
              </Col>
            </Row>
          </Form>
</Dialog>

點(diǎn)擊彈窗的時(shí)候,this.state.sendFee已經(jīng)有值了,但input里的initValue沒起作用,彈窗里的input還是空的,是什么原因呢,我把visible的setstate放在數(shù)據(jù)setstate的回調(diào)里設(shè)置也不行。

回答
編輯回答
清夢

已找到原因,因?yàn)閕nitValue只會在第一次render的時(shí)候觸發(fā)

2017年5月28日 02:08