我有一个简单的组件,它应该将不同类型的字段呈现到我的表单组件中:
import React from "react";
export default class Field extends React.Component {
  render() {
    switch (this.props.type) {
      case 'textarea': {
        return (
          <div className="col-xs-12">
            <textarea
              placeholder={this.props.placeholder}
              name={this.props.name}
            >
            </textarea>
          </div>
          )
      }
      case 'text': {
        return (
          <div className="col-md-6 col-lg-4">
            <input
              type="text"
              placeholder={this.props.placeholder}
              name={this.props.name}
            />
          </div>
        )
      }
    }
  }
}
我在我的表单组件中使用这个组件,如下所示:
export default class SubmitForm extends React.Component {
  render() {
    return (
        .
        .
        .
        <Field
          type="text"
          placeholder="something"
          name="something"
        />
        <Field
          type="textarea"
          placeholder="another"
          name="othername"
        />
        .
        .
        .
    )
  }
}
我的想法是以某种方式实现我的字段组件,以便能够使用点符号,如使用点符号用于 JSX 组件中所述,我已经看到了许多其他库,我希望能够像这样使用这个组件:
<Field.Text name="sth" placeholder="sth" />
<Field.TextArea name="other" placeholder="other stuff" /> 
但我不能像 React 文档中提到的那样做。我怎样才能做到这一点?