Created
September 16, 2016 04:03
-
-
Save victoraugust/4e01b5535e228a6f6ebdbcff347d9bbb to your computer and use it in GitHub Desktop.
React: counter
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
import React from "react"; | |
import Message from "./Message"; | |
import Button from "./Button"; | |
class Appblah extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { changeNumber: 1 } | |
this.handleClick = this.handleClick.bind(this); | |
} | |
handleClick() { | |
let changeNumber = this.state.changeNumber; | |
changeNumber += 1; | |
this.setState({changeNumber:changeNumber}); | |
} | |
render() { | |
return ( | |
<div> | |
<Message text={this.state.changeNumber} /> | |
<Button text="Add One" onClick={this.handleClick} /> | |
</div> | |
); | |
} | |
} |
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
import React, { Component } from 'react'; | |
import Appblah from "./components/"; | |
class Main extends Component { | |
render() { | |
return ( | |
<div className="App"> | |
<Appblah /> | |
</div> | |
); | |
} | |
} | |
export default Main; |
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
import React from "react"; | |
const Message = ({text}) => ( | |
<div>{text}</div> | |
); | |
Message.propTypes = { | |
text: React.PropTypes.number.isRequired | |
}; | |
export default Message; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment