React Base Fiddle (JSX)
Starting point for creating JSFiddles with React.
by Diana Lemen
HTML
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<div id="container">
<!-- This element's contents will be replaced with your component. -->
</div>
Babel + JSX
class Hello extends React.Component {
constructor(){
super();
this.state = {
prediction: {
home: 0,
away: 0,
},
};
this.updatePrediction = this.updatePrediction.bind(this);
}
updatePrediction() {
const result = '2';
const location = 'home';
let prediction = { home: 0, away: 0, }
if(location === 'away'){
prediction.away = result;
} else {
prediction.home = result;
};
this.setState({ prediction });
}
render() {
return (
<div><div>Hello {this.state.prediction.home},hello {this.state.prediction.away}</div>
<button onClick={this.updatePrediction}>
save
</button></div>
)
}
}
ReactDOM.render(
<Hello name="World" />,
document.getElementById('container')
);