反应设置状态不能在键盘上解雇?

时间:2019-11-14 17:07:04

标签: reactjs react-native

我有一个像这样的简单函数,我只是从react文档中复制了它,警报效果完美,但是即使我设置了简单的setstate,我的函数changeDescription也不起作用我做错了什么?

constructor(props) {
    super(props);



    this.changeDescription = this.changeDescription.bind(this);
    this.sendDescription = this.sendDescription.bind(this);
    this._keyboardDidHide = this._keyboardDidHide.bind(this);

  }
      componentDidMount() {
        this.keyboardDidShowListener = Keyboard.addListener(
          'keyboardDidShow',
          this._keyboardDidShow,
        );
        this.keyboardDidHideListener = Keyboard.addListener(
          'keyboardDidHide',
          this._keyboardDidHide,
        );
      }

      componentWillUnmount() {
        this.keyboardDidShowListener.remove();
        this.keyboardDidHideListener.remove();
      }

      _keyboardDidHide() {

        const { member } = this.props;

        alert(member.description)
        this.changeDescription('ok')
      }


      changeDescription = (val) => {

        // console.log(val)

        this.setState({ description: val })

      }



 <Textarea

                defaultValue={member.description}
                onChangeText={v => this.changeDescription(v)}



              /> 

1 个答案:

答案 0 :(得分:2)

我的猜测是,您只需要设置Textarea的值

<Textarea
  defaultValue={member.description}
  onChangeText={v => this.changeDescription(v)}
  value={this.state.description} />