Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. // whenever we're using JSX, we need to import React
  2. import React, { useState } from "react";
  3.  
  4. const Hooks = props => {
  5. // [current value, sets/assigns the new value ] = useState(initial value)
  6. const [count, setCount] = useState(props.initialCount);
  7.  
  8. // naming convention should describe the function
  9.  
  10. const tagahawakNgPagdagdag = () => {
  11. // console.log("clicker");
  12. setCount(bilang => ++bilang);
  13. };
  14.  
  15. const tagahawakNgPagbawas = () => {
  16. console.log("clicker");
  17. setCount(bilang => --bilang);
  18. };
  19.  
  20. return (
  21. <div>
  22. <p>Hello from the Hooks Component</p>
  23. <p>{props.isaPang + " " + props.initialCount}</p>
  24. <p>display current count: {count}</p>
  25. <button onClick={tagahawakNgPagdagdag}>increment</button>
  26. <button onClick={tagahawakNgPagbawas}>decrement</button>
  27. </div>
  28. );
  29. };
  30.  
  31. // export the Hooks component
  32. export default Hooks;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement