简体   繁体   English

react-bootstrap 表单组件

[英]react-bootstrap Form component

I have tried several times to use the <Form> and <FormControl> components.我曾多次尝试使用<Form><FormControl>组件。 Everytime I use I keep getting same erros:每次我使用我都会遇到同样的错误:

"warning.js?8a56:45 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 App ." “warning.js?8a56:45 警告:React.createElement:类型不应为空、未定义、布尔值或数字。它应该是字符串(对于 DOM 元素)或 ReactClass(对于复合组件)。检查渲染方法的App 。”

"Uncaught Invariant Violation: 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 App ." “未捕获的不变违规:元素类型无效:应为字符串(对于内置组件)或类/函数(对于复合组件),但得到:未定义。检查App的渲染方法。”

Even with this basic example:即使使用这个基本示例:

import React, {Component} from 'react';
import {FormControl, FormGroup, ControlLabel, HelpBlock, Checkbox, Radio, Button} from 'react-bootstrap';

export default class App extends Component {
  render() {
    return (
      <form>
        <FormGroup controlId="formControlsText">
          <ControlLabel>Text</ControlLabel>
          <FormControl type="text" placeholder="Enter text" />
        </FormGroup>

        <Button type="submit">
          Submit
        </Button>
      </form>
    );
  }
}

Any ideas?有什么想法吗?

更新 npm-package 这些组件在 react-bootstrap 中是新的。

Import your React-Bootstrap components like this:像这样导入你的 React-Bootstrap 组件:

import FormControl from 'react-bootstrap/lib/FormControl';

That helped me to get rid of the same error when using react-bootstrap 0.31.这帮助我在使用 react-bootstrap 0.31 时摆脱了同样的错误。

I had a somewhat related issue and discovered they removed ControlLabel replacing it with FormLabel in more recent versions.我有一个有点相关的问题,发现他们删除了ControlLabel ,在更新的版本中用FormLabel替换它。

Change改变

import {FormControl, FormGroup, ControlLabel, etc... } from 'react-bootstrap';

To

import {FormControl, FormGroup, FormLabel, etc... } from 'react-bootstrap';

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM