简体   繁体   English

警告:React.createElement:类型无效——需要一个字符串

[英]Warning: React.createElement: type is invalid — expected a string

I'm a complete beginner at web development + react, and am running into a problem as I try to render an imported component.我是 Web 开发 + react 的完全初学者,并且在尝试渲染导入的组件时遇到了问题。

I'm trying to render the following component: https://www.npmjs.com/package/react-launch-gauge我正在尝试呈现以下组件: https : //www.npmjs.com/package/react-launch-gauge

However, when i run, 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: object.

What am I doing wrong?我做错了什么? My code is below我的代码在下面

App.jsx应用程序.jsx

import React from 'react';
import Gauge from 'react-launch-gauge';

class App extends React.Component {
    constructor(props, context) {
        super(props, context)
    }
    render() {
        return (
            <div>
                <Gauge title={'Points'} value={42} max={100} />
            </div>
        );
    }
}
export default App;

main.js主文件

import React from 'react';
import ReactDOM from 'react-dom';
import App from './App.jsx';

ReactDOM.render(<App />, document.getElementById('app'));

webpack.config.js webpack.config.js

var config = {
   entry: './main.js',
   output: {
      path:'/',
      filename: 'index.js',
   },
   devServer: {
      inline: true,
      port: 8080
   },
   module: {
      loaders: [
         {
            test: /\.jsx?$/,
            exclude: /node_modules/,
            loader: 'babel-loader',
            query: {
               presets: ['es2015', 'react']
            }
         }
      ]
   }
}
module.exports = config;

package.json包.json

{
  "name": "iw",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "webpack-dev-server --hot"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "react-launch-gauge": "^0.2.3",
    "webpack": "^3.11.0",
    "webpack-dev-server": "^2.11.1"
  }
}

I believe you'd need to supply constructor to properly initialize App Component, like so:我相信您需要提供constructor来正确初始化App组件,如下所示:

App.jsx应用程序.jsx

import React from 'react';
import Gauge from 'react-launch-gauge';

class App extends React.Component {
    constructor(props, context) {
        super(props, context)
    }

    render() {
        return (
            <div>
                <Gauge title={'Points'} value={42} max={100} />
            </div>
        );
    }
}
export default App;

I have meet same problem like you, this reason is that Gauge has not defined.我也遇到过和你一样的问题,这个原因是 Gauge 没有定义。 so you must definde it with basic structure and export it , you will solve it所以你必须用基本结构定义它并导出它,你会解决它在此处输入图片说明

and like this像这样在此处输入图片说明

暂无
暂无

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

相关问题 警告:React.createElement:类型无效——需要一个字符串 - Warning: React.createElement: type is invalid -- expected a string React 和 Typescript,警告:React.createElement:类型无效——需要一个字符串但得到:未定义 - React and Typescript, Warning: React.createElement: type is invalid -- expected a string but got: undefined 警告:React.createElement:类型无效-预期为字符串(对于内置组件) - Warning: React.createElement: type is invalid — expected a string (for built-in components) 警告:React.createElement:类型无效 - 需要一个字符串(对于内置组件)或一个类/函数(对于复合组件) - Warning: React.createElement: type is invalid — expected a string (for built-in components) or a class/function (for composite components) 警告:React.createElement:类型无效 - 期望字符串或类/函数,但得到:未定义 - Warning: React.createElement: type is invalid — expected a string or a class/function but got: undefined React:警告:React.createElement:类型无效 - React: Warning: React.createElement: type is invalid React.createElement: type is invalid -- 期望一个字符串或 function - React.createElement: type is invalid --expected a string or function ReactJS-错误消息:React.createElement:类型无效-预期为字符串 - ReactJS - Error Message: React.createElement: type is invalid — expected a string 更改 svg 颜色:React.createElement:类型无效 — 应为字符串 - Change svg color : React.createElement: type is invalid — expected a string React.createElement:类型无效-预期为字符串-index.js - React.createElement: type is invalid — expected a string — index.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM