[英]React Typescript error in TextArea : Type 'string' is not assignable to type number
<textarea rows='3'
className='form-control'
placeholder='Enter About your description'/>
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.