2017-06-15 124 views
-1

我想學反應,並跨越這些代碼來在網站上:https://www.reactenlightenment.com/react-state/8.2.html什麼是changeMood功能的其他參數

我明白的代碼做什麼,但無法瞭解什麼是參數「A」在改變功能。刪除代碼後運行代碼,代碼運行良好。

var MoodComponent = React.createClass({ 
    getInitialState: function() { 
    return {mood: ':|'}; 
    }, 
    changeMood:function(event, a){ 
    const moods = [':)',':|',':(']; 
    const current = moods.indexOf(event.target.textContent); 
    this.setState({mood: current === 2 ? moods[0] : moods[current+1]}); 
    }, 
    render: function() { 
     return (
     <span style={{fontSize:'60',border:'1px solid #333',cursor:'pointer'}} 
       onClick={this.changeMood}> 
       {this.state.mood} 
     </span> 
     ) 
    } 
}); 

回答

0

這並不意味着什麼。

onClick只發送1個參數,這是一個由React創建的合成事件,用於處理跨瀏覽器兼容性。

欲瞭解更多信息,請檢查React docs對處理事件的

+0

它是一個打字錯誤,它被列入代碼? –

+0

我相信是這樣,因爲它不在那個範圍內使用 – BravoZulu

+0

感謝您的信息 –

相關問題