ReactJS 输入类型 = "text" maxLength 在作为道具传递时不起作用

ReactJS input type = "text" maxLength is not working when passed as props

我正在尝试将 maxLength 作为道具传递给,但它不起作用。任何人都可以帮忙吗?谢谢!

以下是两个组成部分:

 <Input
        id="creategroup-group-and-description-textfield"
        value={value}
        type="text"
        multiline={this.props.multiline}
        rowsMax={this.props.rowsMax}
        maxLength={this.props.maxLength}
        onChange={this.handleInputChange}
        placeholder={this.props.placeholder}
      />



     <TextFieldWithTitle
          title="Group Name"
          maxLength={3}
          multiline={false}
          placeholder="e.g.Study and Workout"
        />

我终于想出了答案,并决定把它放在这里,以供将来可能有相同问题的人:)

回答: 如果你想在 React 中将 maxLength 作为道具传递。你应该使用:

inputprops = {{maxLength = num}} (note: num can be any positive num you want. No {} and "" needed.

然后在领取这个道具的地方写上:

inputprops = {this.props.inputprops} 

要限制输入长度,写:

<Input 
inputprops={{maxLength: 100(e.g.)}}
/>

注意:Inputprops 和 inputprops 在 React 中是两个不同的东西。小心。