Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import './App.css';
  3. import Clock from './Clock';
  4. import {FormGroup, FormControl, Button} from 'react-bootstrap';
  5.  
  6. class App extends Component {
  7. constructor(props) {
  8. super(props);
  9. this.state = {
  10. deadline: 'December 25 2017',
  11. newDeadline: ''
  12. }
  13. }
  14.  
  15. updateDeadline() {
  16. if (isNaN(Date.parse(this.state.newDeadline)) || this.state.newDeadline === '') {
  17. this.setState({deadline: this.state.deadline});
  18. } else {
  19. this.setState({deadline: this.state.newDeadline})
  20. }
  21. }
  22. // should I keep this update function separate as is or
  23. // can I save 3 lines of code and embed
  24. // ```this.setState({newDeadline: event.target.value})```
  25. // directly in the callback function below?
  26. // eg onChange={event => this.setState({newDeadline: event.target.value}}
  27. updateNewDeadline(event) {
  28. this.setState({newDeadline: event.target.value})
  29. }
  30.  
  31. render() {
  32. return (
  33. <div className="app">
  34. <div className="app-title">Countdown To {this.state.deadline}</div>
  35. <Clock deadline={this.state.deadline} />
  36. <form className="app-form">
  37. <FormGroup>
  38. <FormControl className="deadline-input"
  39. placeholder='Enter a new date'
  40. onChange={event => this.updateNewDeadline(event)}
  41. />
  42. <Button bsStyle="primary" block onClick={() => this.updateDeadline()}>Submit</Button>
  43. </FormGroup>
  44. </form>
  45. </div>
  46. )
  47. }
  48. }
  49.  
  50. export default App;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement