Advertisement
Guest User

quote test

a guest
Jan 20th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. class QuoteGenerator extends React.Component {
  2. constructor() {
  3. super();
  4. this.state = {
  5. url: "https://got-quotes.herokuapp.com/quotes",
  6. quote: "",
  7. character: ""
  8. }
  9. this.handleClick = this.handleClick.bind(this);
  10. this.handleTweet = this.handleTweet.bind(this);
  11. }
  12.  
  13. componentDidMount() {
  14. fetch(this.state.url)
  15. .then(function(res) {
  16. return res.json();
  17. })
  18. .then(
  19. function(data) {
  20. this.setState({
  21. quote: data.quote,
  22. character: data.character
  23. });
  24. }.bind(this)
  25. );
  26. }
  27.  
  28. handleClick() {
  29. fetch(this.state.url)
  30. .then(function(res) {
  31. return res.json();
  32. })
  33. .then(
  34. function(data) {
  35. this.setState({
  36. quote: data.quote,
  37. character: data.character
  38. });
  39. }.bind(this)
  40. );
  41. }
  42.  
  43. handleTweet() { window.open('https://twitter.com/intent/tweet?text=' + '{this.state.quote}');
  44. }
  45.  
  46. render() {
  47. const quoteStyle = {
  48. backgroundColor: '#fff'
  49. }
  50.  
  51. return (
  52. <div className="container-fluid bg-primary">
  53. <div className="row">
  54. <div className="col-sm-12 bg-secondary">
  55. <p>{this.state.quote}</p>
  56. </div>
  57. </div>
  58. <div className="row">
  59. <div className="col-sm-4 col-push-sm-4 bg-success">
  60. <a
  61. onClick={this.handleTweet}
  62. class="fa fa-twitter">Tweet this</a>
  63. </div>
  64. <div className="col-sm-4 col-pull-sm-8 bg-warning">
  65. <p>-{this.state.character}</p>
  66. </div>
  67. <div className="col-sm-4">
  68. <button className="btn btn-primary"
  69. onClick={this.handleClick}>New quote</button>
  70. </div>
  71. </div>
  72. </div>
  73. );
  74. }
  75. }
  76. ReactDOM.render(<QuoteGenerator />, document.getElementById("app"));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement