简体   繁体   English

元素类型无效:检查渲染方法

[英]Element type is invalid: check the render method

Please help, I feel like I've tried everything and can't seem to fix this.请帮忙,我觉得我已经尝试了所有方法,但似乎无法解决这个问题。 I'm not even sure what the error means.我什至不确定错误是什么意思。 Please help!请帮忙!

Here is my code:这是我的代码:

import React from 'react';
import FBPost from './fbpost';

import {
  Upload,
  Icon,
  Divider,
  Input,
  Select,
  TimePicker,
  Button,
  InputNumber,
  Checkbox,
} from 'antd';

import './ask.css';

const { Option } = Select;

export class Ask extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      avtars: [],
      images: [],
      includeLike: false,
      includeLove: false,
      includeHaha: false,
      includeWow: false,
      includeSad: false,
      includeAngry: false,
      editorShown: true,
    };
  }

 toggleEditor () {
    let { editorShown } = this.state;
    this.setState({ editorShown: !editorShown });
  };

  uploadAvtar ({ fileList }) {this.setState({ avtars: fileList })};

  setTime (time, timeString) {
    this.setState({ time: timeString });
  };

  setPrivacy (value) {
    this.setState({ privacy: value });
  };

  uploadImages  ({ fileList }) {
    const images = fileList.map(file => {
      return file.thumbUrl;
    });
    this.setState({ images });
  };

  includeLike () {
    let { includeLike } = this.state;
    this.setState({ includeLike: !includeLike });
  };

  includeLove () {
    let { includeLove } = this.state;
    this.setState({ includeLove: !includeLove });
  };

  includeHaha () {
    let { includeHaha } = this.state;
    this.setState({ includeHaha: !includeHaha });
  };

  includeWow () {
    let { includeWow } = this.state;
    this.setState({ includeWow: !includeWow });
  };

  includeSad () {
    let { includeSad } = this.state;
    this.setState({ includeSad: !includeSad });
  };

   includeAngry () {
    let { includeAngry } = this.state;
    this.setState({ includeAngry: !includeAngry });
  };

  render() {
    const {
      avtars,
      name,
      caption,
      time,
      privacy,
      likes,
      images,
      editorShown,
    } = this.state;
    let {
      includeLike,
      includeLove,
      includeHaha,
      includeWow,
      includeSad,
      includeAngry,
    } = this.state;

    const uploadButton = (
      <div>
        <Icon type="plus" />
        <div className="ant-upload-text">Upload Avtar</div>
      </div>
    );

    return (
      <div className="App">
        <Button onClick={this.toggleEditor} className="editor-hide-button">
          {editorShown ? 'Hide Editor' : 'Show Editor'}
        </Button>

        {editorShown && (
          <div className="editor">
            <div className="editor_avtar">
              <Upload
                action="//jsonplaceholder.typicode.com/posts/"
                listType="picture-card"
                onPreview={() => {}}
                accept="image/*"
                onChange={this.uploadAvtar}
              >
                {avtars.length >= 1 ? null : uploadButton}
              </Upload>
            </div>

            <div className="editor_name">
              <Input
                placeholder="Your Name"
                prefix={
                  <Icon type="user" style={{ color: 'rgba(0,0,0,.25)' }} />
                }
                onChange={e => this.setState({ name: e.target.value })}
              />
            </div>

            <div className="editor_time_privacy">
              <TimePicker
                onChange={this.setTime}
                use12Hours
                format="h:mm a"
                className="select-time"
                placeholder="Select Time"
              />

              <Select
                defaultValue="Privacy"
                className="editor-privacy"
                onChange={this.setPrivacy}
              >
                <Option value="Privacy" disabled>
                  Privacy
                </Option>
                <Option value="public">Public</Option>
                <Option value="friends">Friends</Option>
              </Select>
            </div>

            <div className="editor_caption">
              <Input.TextArea
                rows={1}
                placeholder="Some Caption"
                onChange={e => this.setState({ caption: e.target.value })}
              />
            </div>

            <Divider />

            <p>
              <b>Upload Pictures:</b> &nbsp; Upload Multiples by clicking CTRL
              ;)
            </p>
            <Upload
              action="//jsonplaceholder.typicode.com/posts/"
              listType="picture"
              multiple
              onPreview={() => {}}
              accept="image/*"
              onChange={this.uploadImages}
            >
              <Button>
                <Icon type="upload" /> Upload
              </Button>
            </Upload>

            <Divider />

            <InputNumber
              style={{ width: '100%' }}
              placeholder="Initial Likes"
              onChange={value => this.setState({ likes: value })}
            />

            <br />
            <br />
            <b>Includes:</b>
            <br />
            <Checkbox
              onChange={this.includeLike}
              style={{ width: 'calc(33% - 10px)', marginLeft: 10 }}
            >
              Likes
            </Checkbox>
            <Checkbox
              onChange={this.includeLove}
              style={{ width: 'calc(33% - 10px)', marginLeft: 10 }}
            >
              Love
            </Checkbox>
            <Checkbox
              onChange={this.includeHaha}
              style={{ width: 'calc(33% - 10px)', marginLeft: 10 }}
            >
              Haha
            </Checkbox>
            <Checkbox
              onChange={this.includeWow}
              style={{ width: 'calc(33% - 10px)', marginLeft: 10 }}
            >
              WoW
            </Checkbox>
            <Checkbox
              onChange={this.includeSad}
              style={{ width: 'calc(33% - 10px)', marginLeft: 10 }}
            >
              Sad
            </Checkbox>
            <Checkbox
              onChange={this.includeAngry}
              style={{ width: 'calc(33% - 10px)', marginLeft: 10 }}
            >
              Angry
            </Checkbox>
          </div>
        )}

        <div className="result">
          <FBPost
            avtar={avtars[0] ? avtars[0].thumbUrl : false}
            name={name}
            time={time}
            privacy={privacy}
            caption={caption}
            images={images}
            likes={likes}
            includeLike={includeLike}
            includeLove={includeLove}
            includeHaha={includeHaha}
            includeWow={includeWow}
            includeSad={includeSad}
            includeAngry={includeAngry}
          />
        </div>
        <div style={{ height: 200, width: '100%' }}>&nbsp;</div>
      </div>
    );
  }
}

I keep getting the following error:我不断收到以下错误:

Warning: React.createElement: type is invalid -- expected a string (for built-in components) or >a class/function (for composite components) but got: %s.%s%s undefined You likely forgot to export your component from the file it's defined in, or you might have >mixed up default and named imports.警告:React.createElement:类型无效——需要一个字符串(对于内置组件)或>一个类/函数(对于复合组件)但得到:%s.%s%s undefined 你可能忘记导出你的组件从它定义的文件中,或者你可能已经>混合了默认和命名的导入。

Check the render method of Ask .检查Ask的渲染方法。

at Ask (:735:5) at div at App Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a >class/function (for composite components) but got: %s.%s%s undefined You likely forgot to export your component from the file it's defined in, or you might have >mixed up default and named imports.在应用程序警告的 div 处询问 (:735:5):React.createElement:类型无效 - 需要一个字符串(对于内置组件)或 > 类/函数(对于复合组件),但得到:%s。 %s%s undefined 您可能忘记从定义组件的文件中导出组件,或者您可能 > 混淆了默认导入和命名导入。

Check the render method of Ask .检查Ask的渲染方法。

at Ask (:735:5) at div at App Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a >class/function (for composite components) but got: %s.%s%s undefined You likely forgot to export your component from the file it's defined in, or you might have >mixed up default and named imports.在应用程序警告的 div 处询问 (:735:5):React.createElement:类型无效 - 需要一个字符串(对于内置组件)或 > 类/函数(对于复合组件),但得到:%s。 %s%s undefined 您可能忘记从定义组件的文件中导出组件,或者您可能 > 混淆了默认导入和命名导入。

Check the render method of Ask .检查Ask的渲染方法。

at Ask (:735:5) at div at App Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.在应用程序错误的 div 处询问 (:735:5):元素类型无效:预期为字符串(对于内置组件)或类/函数(对于复合组件),但得到:未定义。 You likely forgot to export your component from >the file it's defined in, or you might have mixed up default and named imports.您可能忘记从 > 定义组件的文件中导出组件,或者您可能混淆了默认导入和命名导入。

Check the render method of Ask .检查Ask的渲染方法。 at createFiberFromTypeAndProps (:19987:27) at createFiberFromElement (:20009:25) at createChild (:10805:36) at reconcileChildrenArray (:11008:35) at reconcileChildFibers (:11285:26) at reconcileChildren (:14348:39) at updateHostComponent$1 (:14837:13) at beginWork (:15940:24) at HTMLUnknownElement.callCallback (:3113:24) Error: Element type is invalid: expected a string (for built-in components) or a class/function >(for composite components) but got: undefined.在 createFiberFromTypeAndProps (:19987:27) 在 createFiberFromElement (:20009:25) 在 createChild (:10805:36) 在 reconcileChildrenArray (:11008:35) 在 reconcileChildFibers (:11285:26) 在 reconcileChildren (:14348:39) 在 updateHostComponent $1 (:14837:13) at beginWork (:15940:24) at HTMLUnknownElement.callCallback (:3113:24) 错误:元素类型无效:需要一个字符串(对于内置组件)或一个类/函数>(对于复合组件)但得到:未定义。 You likely forgot to export your component from the >file it's defined in, or you might have mixed up default and named imports.您可能忘记从定义它的 >file 导出组件,或者您可能混淆了默认导入和命名导入。

Issue is due to import {..., Icon, ... } from 'antd';问题是由于import {..., Icon, ... } from 'antd'; . .

Check the v3 to v4 migration guide查看v3 到 v4 迁移指南

Now you need to:现在你需要:

  • Install the "@ant-design/compatible" npm package安装“@ant-design/compatible” npm package
  • Remove Icon from existing import from antdantd的现有导入中删除Icon
  • Add import { Icon } from "@ant-design/compatible";添加import { Icon } from "@ant-design/compatible";

Or you will need to complete the full migration.或者,您将需要完成完整迁移。

暂无
暂无

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

相关问题 ReactJs元素类型无效检查render方法 - ReactJs Element type is invalid Check the render method React Native Element Type无效。 选中渲染方法 - React Native Element Type is Invalid. Check Render Method 组件异常:元素类型无效,请检查应用程序的渲染方法 - Component Exception: Element Type is Invalid, check render Method of app 元素类型无效:检查提供者的渲染方法(React Native) - Element type is invalid: Check render method of Providers (React Native) 错误:元素类型无效,检查相机的渲染方法 - Error: Element type is invalid with Check the render method of Camera 检查`Drawer`的渲染方法。 元素类型无效错误 - Check the render method of `Drawer`. Element type is invalid Error 错误:元素类型无效,检查 React Native 中的渲染方法 - Error: Element type is invalid with Check the render method in React Native 不变违规:元素类型无效:预期为字符串或类/函数,但获得了:对象。 检查的渲染方法 - Invariant Violation: Element type is invalid: expected a string or a class/function but got: object. Check the render method of 元素类型无效:期望一个字符串(对于内置组件)...检查`App`的render方法 - Element type is invalid: expected a string (for built-in components) … Check the render method of `App` 不变违规:元素类型无效:预期是字符串或类,但得到:未定义。 检查`MyApp`的渲染方法 - Invariant Violation: Element type is invalid: expected a string or a class but got: undefined. Check the render method of `MyApp`
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM