Guest User

Untitled

a guest
Jul 22nd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. <script src="node_modules/react/umd/react.development.js"></script>
  2. <script src="node_modules/react-dom/umd/react-dom.development.js"></script>
  3. <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
  4.  
  5. <div id="root"></div>
  6.  
  7. <script type="text/babel">
  8. class List extends React.Component {
  9. constructor(props) {
  10. super(props);
  11. this.state = {
  12. votes: 0,
  13. }
  14. this.items = [];
  15. this.handleClick = this.handleClick.bind(this);
  16. }
  17.  
  18. handleClick(event) {
  19. const votes = this.state.votes;
  20. this.setState({
  21. votes: votes + 1
  22. })
  23. }
  24.  
  25. render() {
  26. return (
  27. <div>
  28. <h1>Vote Your JS Library!</h1>
  29. <ul>
  30. { this.props.items.map((item) =>
  31. <li key = {item}>
  32. {this.state.votes}
  33. {item}
  34. <button onClick = { () => this.handleClick() }> + </button>
  35. </li>
  36. ) }
  37. </ul>
  38. </div>
  39. )
  40. }
  41. }
  42.  
  43. ReactDOM.render(<List items= { ['React', 'Vue', 'Angular', 'Ember'] } />, document.getElementById('root'));
  44. </script>
Add Comment
Please, Sign In to add comment