Guest User

Untitled

a guest
Jun 20th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. // JSX - JavaScript XML
  2.  
  3. var app ={
  4. title: 'Focus App',
  5. subtitle: 'The TODO App',
  6. options: ['One', 'Two']
  7. }
  8.  
  9. var template = (
  10. <div>
  11. <h1>{app.title}</h1>
  12. {app.subtitle && <p>{app.subtitle}</p>}
  13. <p>{app.options.length > 0 ? 'Here are your options' : 'No options' }</p>
  14. <p></p>
  15. <ol>
  16. <li>Item one</li>
  17. <li>Item two</li>
  18. </ol>
  19.  
  20. </div>
  21. );
  22.  
  23. let count = 0;
  24.  
  25. const addOne = () => {
  26. count++;
  27. renderCounterApp();
  28. };
  29. const minusOne = () => {
  30. count--;
  31. renderCounterApp();
  32. };
  33. const reset = () => {
  34. count = 0;
  35. renderCounterApp();
  36. };
  37.  
  38. var appRoot = document.getElementById('app');
  39.  
  40. const renderCounterApp = () => {
  41. const templateTwo = (
  42. <div className="container">
  43. <br></br>
  44. <br></br>
  45. <br></br>
  46. <h1>Count : {count}</h1>
  47. <button id="my-id" className="button btn btn-outline-danger btn-sm" onClick={addOne} >&nbsp;&nbsp;&nbsp;&nbsp; +1 &nbsp;&nbsp;&nbsp;&nbsp;</button> &nbsp;&nbsp;
  48. <button id="my-id" className="button btn btn-outline-danger btn-sm" onClick={minusOne} >&nbsp;&nbsp;&nbsp;&nbsp; -1 &nbsp;&nbsp;&nbsp;&nbsp;</button> <br></br><br></br>
  49. <button id="my-id" className="button btn btn-outline-danger btn-sm" onClick={reset} >&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Reset
  50. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;</button>
  51. </div>
  52. );
  53.  
  54. ReactDOM.render(templateTwo, appRoot);
  55.  
  56. };
  57. renderCounterApp();
Add Comment
Please, Sign In to add comment