简体   繁体   English

TextArea 中的 React Typescript 错误:类型“字符串”不可分配给类型编号

[英]React Typescript error in TextArea : Type 'string' is not assignable to type number

<textarea rows='3' 
  className='form-control' 
  placeholder='Enter About your description'/>

The expected type comes from property 'rows' which is declared here on type 'DetailedHTMLProps, HTMLTextAreaElement>'预期的类型来自属性 'rows',它在类型 'DetailedHTMLProps, HTMLTextAreaElement>' 上声明

截屏

Try this:尝试这个:

<textarea rows={3} 
  className='form-control' 
  placeholder='Enter About your description'/>

the row property requires a number, not a string. row属性需要一个数字,而不是一个字符串。 Also you will need to update the value of the textarea like this:您还需要像这样更新 textarea 的值:

<textarea 
  name="description"
  value={formValues.description}
  rows={3} 
  className='form-control' 
  placeholder='Enter About your description'
  onChange={evt=>handleInputChange(evt)}/>

The handleInputChange function below:下面的 handleInputChange 函数:

// You can define an interface to type the formValues object like this
interface formValuesInterface {
    description: string
}

// Keep the description value in the state like this
const [formValues, setFormValues] = React.useState<formValuesInterface>({description: ''})

const handleInputChange = (evt: React.ChangeEvent<HTMLInputElement>)=> {
    const { name, type } = evt.target
    const value = target.type === 'checkbox' ? target.checked : target.value;
    setFormValues({ ...formValues, [name]: value })
}

Check out React forms for more information查看React 表单以获取更多信息

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 打字稿错误:类型 &#39;string&#39; 不能分配给类型 &#39;“allName” | 反应钩子形式的`allName.${number}.nestedArray`&#39; - Typescript error: Type 'string' is not assignable to type '“allName” | `allName.${number}.nestedArray`' in react hook form 在反应 typescript 中,类型“字符串”不可分配给类型“从不”并且类型“未知”不可分配给类型“从不”错误 - Type 'string' is not assignable to type 'never' and Type 'unknown' is not assignable to type 'never' error in react typescript Typescript React - 类型“字符串”不可分配给类型“外观” - Typescript React - Type 'string' is not assignable to type 'Appearance' React TypeScript:类型“string []”不可分配给类型“never []” - React TypeScript: Type 'string[]' is not assignable to type 'never[]' Typescript 错误:: 类型“数字”不可分配给类型“从不” - Typescript error :: Type 'number' is not assignable to type 'never' TypeScript错误:类型“…”不能分配给类型“ IntrinsicAttributes&Number” - TypeScript error : Type '…' is not assignable to type 'IntrinsicAttributes & Number' TypeScript 错误:类型“字符串”不可分配给排版类型 - TypeScript error: Type 'string' is not assignable to type for Typography 类型“string[]”不可分配给类型“never[]”。 Typescript 错误 - Type 'string[]' is not assignable to type 'never[]'. Typescript Error 输入&#39;{percentage:number; }&#39;不能为CircularProgressbar分配React Typescript - Type '{ percentage: number; }' is not assignable React Typescript for the CircularProgressbar onClick 无法分配给 TypeScript 反应中的类型“IntrinsicAttributes”错误 - onClick not assignable to type 'IntrinsicAttributes' error in TypeScript React
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM