如何检查新输入在 React Native ListView 数据源中是否唯一

How to check that new input will be unique in react native ListView data-source

我需要检查将添加到数据源的新输入是否已包含在其中。

 _handleSendButtonPress = () => {
    const textArray = this.state.dataSource._dataBlob.s1;
// Here I need to check that this.state.inputValue is in textArray already
    textArray.push(this.state.inputValue);
    this.setState(() => ({
      dataSource: this.state.dataSource.cloneWithRows(textArray),
      inputValue: '',     
    }));
  };

如果我理解正确并且 textArray 确实是一个数组,那么这应该有效:

_handleSendButtonPress = () => {
  const textArray = this.state.dataSource._dataBlob.s1;
  !textArray.includes(this.state.inputValue) && (
    textArray.push(this.state.inputValue);
    this.setState(() => ({
    dataSource: this.state.dataSource.cloneWithRows(textArray),
    inputValue: '',     
  }));
  )
};