1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/examples/with-custom-babel-config/pages/index.js
Arunoda Susiripala 1719738ed1 Allow to customize our babel configuration (#466)
* Add a way to customize babel configurations.

* Add babel configuration docs to README.
2016-12-21 17:36:00 -08:00

47 lines
960 B
JavaScript

import React from 'react'
export default class MyLuckNo extends React.Component {
constructor (...args) {
super(...args)
this.state = { randomNo: null }
}
componentDidMount () {
this.recalculate()
}
recalculate () {
this.setState({
randomNo: Math.ceil(Math.random() * 100)
})
}
render () {
const { randomNo } = this.state
if (randomNo === null) {
return (<p>Please wait..</p>)
}
// This is an experimental JavaScript feature where we can get with
// using babel-preset-stage-0
const message = do {
if (randomNo < 30) {
'Do not give up. Try again.'
} else if (randomNo < 60) {
'You are a lucky guy'
} else {
'You are soooo lucky!'
}
}
return (
<div>
<h3>Your Lucky number is: "{randomNo}"</h3>
<p>{message}</p>
<button onClick={() => this.recalculate()}>Try Again</button>
</div>
)
}
}