Child to parent communication in React (JSX) without flux

前端 未结 3 1090
悲哀的现实
悲哀的现实 2021-01-02 09:16

I\'m really new to React, and I\'m pulling my hair out trying to solve what seems to me to be a simple problem. Here\'s a picture of the component I\'ve built.

Color

3条回答
  •  没有蜡笔的小新
    2021-01-02 09:49

    You can just pass callback function into child from your parent component, as simple as this:

     
    

    (when using React.createClass all class methods are already bound to this, so you are not required to call .bind(this)).

    Then from ColorButton component you can call this callback as this.props.onColorSelect(...).

    JS Bin example: http://jsbin.com/fivesorume/edit?js,output

提交回复
热议问题