美文网首页
react error

react error

作者: LFBuildMountain | 来源:发表于2018-04-02 15:26 被阅读0次

    ERROR 1

    import React, { Component } from 'react';
    
    ->  const App = React.createClass({
        "displayName":'App',
        getDefaultProps(){
            return {
                totalStars:5
            }
        },
    //omit following code
    
    __WEBPACK_IMPORTED_MODULE_0_react___default.a.createClass is not a function
    

    createClass() function has been deprecated after v1.6

    solution

    class App extends Component{
    }
    

    Erro2

    class App extends React.component{
        constructor(props){
            super(props)
            this.state={
                starSelected:0
            }
        }
    
    TypeError: Super expression must either be null or a function, not undefined
    

    it should be React.Component, not component

    class App extends Component{
    }
    

    error3

    import {Component} from 'react'
    
    import ColorForm from './component/ColorForm'
    
    class App extends Component{
    
        render(){
            return (
            <ColorForm>
    
            </ColorForm>)
        }
    
    }
    
    'React' must be in scope when using JSX
    

    react impose that react must be imported into current module if you want to use JSX syntax in module

    import React,{Component} from 'react'
    

    error4

    class App extends Component{
    
        render(){
            return (
                <ColorForm />
                <ColorList colors={data.colors} />
            )
        }
    }
    
    Adjacent JSX elements must be wrapped in an enclosing tag 
    

    render() of component class should only return a single react element at a time

    class App extends Component{
    
        render(){
            return (
                    <div>
                <ColorForm />
                <ColorList colors={data.colors} />
                    </div>
            )
        }
    }
    

    相关文章

      网友评论

          本文标题:react error

          本文链接:https://www.haomeiwen.com/subject/ymhxhftx.html