Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. // Stateless functional component CurrentDate
  2. // When dealing with stateless functional components, you basically consider props as an argument to a function which returns JSX
  3. // You can access the value of the argument in the function body. With class components, you will see this is a little different
  4. const CurrentDate = (props) => {
  5. return (
  6. <div>
  7. { /* access the date property from Calendar */ }
  8. <p>The current date is: {props.date}</p>
  9. </div>
  10. );
  11. };
  12.  
  13. // ES6 class component Calendar
  14. class Calendar extends React.Component {
  15. constructor(props) {
  16. super(props);
  17. }
  18. render() {
  19. return (
  20. <div>
  21. <h3>What date is it?</h3>
  22. { /* pass in a property to the component CurrentDate with date assigned to the current date from JS's Date object */ }
  23. <CurrentDate date={Date()} />
  24. </div>
  25. );
  26. }
  27. };
  28.  
  29. // render Calendar to the DOM and put it where id='challenge-node' in HTML
  30. ReactDOM.render(
  31. <Calendar />,
  32. document.getElementById('challenge-node');
  33. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement