鍍金池/ 問(wèn)答/HTML/ antd中form表單使用textarea會(huì)報(bào)錯(cuò),該如何解決?

antd中form表單使用textarea會(huì)報(bào)錯(cuò),該如何解決?

先上代碼

import React from 'react';
import { Form, Input, Button, DatePicker, Select } from 'antd';
const FormItem = Form.Item;
const { TextArea } = Input;

class InfoAdd extends React.Component {
  constructor(props) {
    super(props);
  }

  handleSubmit(){
    console.log('handleSubmit');
    }
    
  render() {
        const { getFieldDecorator } = this.props.form;
        

    return (
            <Form onSubmit={this.handleSubmit}>
                <FormItem label="消息內(nèi)容">
                    {getFieldDecorator('INFO_CONTENT')(<TextArea />)}
                </FormItem>                
            </Form>
    )
  }
}

export default Form.create()(InfoAdd);

就會(huì)報(bào)錯(cuò)

Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components). Check the render method of `InfoAdd`.

Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. Check the render method of `InfoAdd`.

將form中的TextArea改為Input替代是可以得,說(shuō)明代碼沒(méi)錯(cuò)誤,
網(wǎng)上搜索錯(cuò)誤信息,說(shuō)是引入不正確,但是官網(wǎng)里對(duì)TextArea引入就是

import { Input } from 'antd';
const { TextArea } = Input;

ReactDOM.render(
  <div>
    <TextArea placeholder="Autosize height based on content lines" autosize />
    <div style={{ margin: '24px 0' }} />
    <TextArea placeholder="Autosize height with minimum and maximum number of lines" autosize={{ minRows: 2, maxRows: 6 }} />
  </div>
, mountNode);

不過(guò)不是在form中,所以想問(wèn)問(wèn)各位 有沒(méi)有什么好的解決方法? 或者是我哪里寫(xiě)錯(cuò)了?

或者在form中,要輸入大量的文本,用哪個(gè)控件代替?

回答
編輯回答
別傷我

antd的textarea可以使用input來(lái)代替,需要加上type=‘textarea’,這樣之后,所有的事件與inputt的都一致了??梢钥纯垂俜轿臋n,寫(xiě)的其實(shí)很詳細(xì)。
代碼如下:

              <Input
                type='textarea'
                placeholder='textarea內(nèi)容'
                autosize={{ minRows: 12 }}
                onChange={this.textareaChange}
              />
2017年10月7日 14:53