Skip to content

Instantly share code, notes, and snippets.

@nhunzaker
Last active July 25, 2016 11:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nhunzaker/79d48674f543a3bf0977667c2513e9ac to your computer and use it in GitHub Desktop.
Save nhunzaker/79d48674f543a3bf0977667c2513e9ac to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>onChange Troubleshooting</title>
</head>
<body>
<div id="container"></div>
<script src="https://fb.me/react-15.2.1.js"></script>
<script src="https://fb.me/react-dom-15.2.1.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.24/browser.min.js"></script>
<script type="text/babel">
var Hello = React.createClass({
getInitialState() {
return {
first: '',
second: ''
}
},
changeDidBubble() {
console.log('bubble!')
},
onFirstChange(event) {
this.setState({
first: event.target.value
})
},
onSecondChange(event) {
console.log("Typeof event.cancelBubble: ", typeof event.nativeEvent.cancelBubble)
event.stopPropagation()
this.setState({
second: event.target.value
})
},
render() {
return (
<div>
<div onChange={ this.changeDidBubble }>
<p>Bubbles:</p>
<input value={ this.state.first } onChange={ this.onFirstChange } />
</div>
<div onChange={ () => console.log('This should never happen') }>
<p>Stops propagation:</p>
<input value={ this.state.second } onChange={ this.onSecondChange } />
</div>
</div>
)
}
})
ReactDOM.render(<Hello />, document.getElementById('container'))
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment