2017-07-30 54 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

相關問題