0

我在 React-Native 中的组件代码如下(请注意我使用的是 native-base,以防结构看起来很奇怪):

class CardIntInput extends React.Component {

  render() {
    return (
      <Card>
        <Form>
          <Item regular>
            <Label> 
              {this.props.info}:
            </Label>
            <Input
              keyboardType = 'number-pad'
              onChangeText = {(text) => {this.props.data} = text}
            />
          </Item>
        </Form>
      </Card>
    )
  }
}

每次我运行代码时,它都会返回上述错误,我已将其隔离到 onChangeText 行。

我对 JS 和 React Native 很陌生,我已经尝试了所有我能想到的,所以我求助于其他人的建议。

我希望我只是忘记了一些简单的事情,但任何建议都将不胜感激

4

2 回答 2

0

以下不会发出错误:

onChangeText = {(text) => { this.props.data.text = text }}

但是,分配 props 数据是一种反模式……请参阅:

于 2019-01-17T16:03:45.730 回答
0

使用打字稿时,如果您将组件文件命名为 .ts 而不是 .tsx,这将引发打字稿错误。将文件重命名为 .tsx

于 2021-09-15T03:26:47.910 回答