Last active
January 30, 2017 05:47
-
-
Save gt3/cd3ff292d228a88a9443d29e432e5e4b 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
let TH = ({value}) => <th >{value}</th> | |
let TD = ({value}) => <td>{value}</td> | |
let Row = ({update, children}) => <tr onClick={update}>{children}</tr> | |
class Printer extends React.Component { | |
constructor(props) { | |
super(props) | |
this.state = {acc: []} | |
this.update = this.update.bind(this) | |
this.mult = this.mult.bind(this) | |
} | |
mult() { | |
let acc = this.state.acc[this.state.acc.length - 1] || this.props.m | |
return acc + this.props.m | |
} | |
update() { | |
let acc = this.state.acc.concat(this.mult()) | |
this.setState({acc}) | |
} | |
render() { | |
return ( | |
<Row update={this.update}> | |
<TH value={this.props.m} /> | |
{ this.state.acc.map(v => <TD key={v} value={v} />) } | |
</Row> | |
) | |
} | |
} | |
let PrintTable = ({m}) => ( | |
<table> | |
<tbody> | |
<Printer m={m} /> | |
</tbody> | |
</table> | |
) | |
let render = node => ReactDOM.render(<PrintTable m={5} />, node) //render multiples of 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment