2017-07-30 56 views
-1

错误看起来是这样的 -的反应,为什么我的控制台说,“无法构造‘评论’

无法构造‘评论’:请使用‘新’运营商,这个DOM对象的构造不能称为作为一个功能

不知道如何使用“新”运营商和它是什么意思谁能帮我

这里是代码 - !?

import React from "react"; 
import {render} from "react-dom"; 



class Board extends React.Component{ 
    state ={comments: ["I like bla", "what next?", "this is the last."]} 

    eachComment(text, i){ 
    return (<Comment key={i}>{text}</Comment>); 
    } 

    render(){ 
    return(
     <div> 
     { 
      this.state.comments.map(this.eachComment) 
     } 
     </div> 
    ); 
    } 
} 

render(<Board/>, window.document.getElementById("example")); 

回答

0

应该是

constructor() { 
this.state ={comments: ["I like bla", "what next?", "this is the last."]} 
} 

代替state ={comments: ["I like bla", "what next?", "this is the last."]}

0

内部为状态的类应该是this.state =这是使得类保存数据并反应组分正在寻找的状态的类

0

你可以尝试这些改变吗?

class Board extends React.Component{ 
    constructor(){ 
    super(); 
    this.state ={comments: ["I like bla", "what next?", "this is the last."]}; 
    } 
... 
} 

并指定eachComment如上render()

价的对象:https://stackoverflow.com/a/28205521/3279391

+0

仍然看到的错误。 – azizul

相关问题