Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import './App.css';
  3.  
  4. var obj = {
  5. width: "200px",
  6. height: "200px",
  7. backgroundColor: "black"
  8. }
  9.  
  10. class App extends Component {
  11. constructor(props){
  12. super(props)
  13. this.state = {
  14. text: '',
  15. count: 5
  16. }
  17. this.func = this.func.bind(this)
  18. this.onChange = this.onChange.bind(this)
  19. this.timer = this.timer.bind(this)
  20. }
  21.  
  22. onChange(e){
  23. this.setState({
  24. text: e.currentTarget.value
  25. })
  26. }
  27.  
  28. func(){
  29. alert(this.state.text)
  30. }
  31.  
  32. timer(){
  33. var t = setInterval(() => {
  34. if(this.state.count === 0){
  35. clearInterval(t)
  36. }else{
  37. this.setState({
  38. count: this.state.count-1
  39. })
  40. }
  41. }, 1000)
  42. }
  43.  
  44. render() {
  45. return (
  46. <div className="App">
  47. <input onChange={this.onChange} />
  48. <h1>{this.state.count}</h1>
  49. <button style={obj} onClick={this.timer}>Hello</button>
  50. </div>
  51. );
  52. }
  53. }
  54.  
  55. export default App;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement