Last active
August 29, 2015 14:23
-
-
Save smontlouis/54cc88efd8dee91c4448 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* EXAMPLE 2 */ | |
//Parent component | |
class App extends React.Component { | |
render() { | |
return <div> | |
<First/> | |
<Second /> | |
</div>; | |
} | |
} | |
//Child 1 | |
class First extends React.Component { | |
click(){ | |
actions.clicked(); | |
} | |
render() { | |
return <div onClick={click}>FIRST</div>; | |
} | |
} | |
//Child 2 | |
class Second extends React.Component { | |
constructor(props){ | |
super(props) | |
this.state = { clicked: true;} | |
} | |
componentWillMount(){ | |
} | |
render() { | |
return <div>SECOND {clicked ? 'CLICKED' : 'OHOH'}</div>; | |
} | |
AppDispatcher.register(function(action)){ | |
switch(action.type){ | |
case 'clickedAction': | |
this.setState({clicked: !this.state.clicked}) | |
break; | |
} | |
} | |
} | |
React.render(<App />, document.getElementById('parentToChild')); | |
//actions.js | |
actions = { | |
clicked: function(){ | |
AppDispatcher.dispatch({ | |
actionType: 'clickedAction', | |
}); | |
}, | |
//anotherActions | |
} | |
//Dispatcher.js | |
let AppDispatcher = new Dispatcher() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment