Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. const App: React.FC = () => {
  2. const defaultCountValue = 0;
  3. const [count, setCount] = useState(defaultCountValue);
  4.  
  5. const handleIncrement = (currentCount: number) => {
  6. setCount(currentCount + 1);
  7. };
  8. const handleDecrement = (currentCount: number) => {
  9. setCount(currentCount - 1);
  10. };
  11.  
  12. const handleReset = () => {
  13. setCount(defaultCountValue);
  14. };
  15.  
  16. return (
  17. <div
  18. style={{
  19. display: "flex",
  20. justifyContent: "center",
  21. height: "50%",
  22. paddingTop: "20%",
  23. }}
  24. >
  25. <label>
  26. Count:
  27. <input value={count} type="number" />
  28. </label>
  29. <button onClick={() => handleIncrement(count)}>+</button>
  30. <button onClick={() => handleDecrement(count)}>-</button>
  31. <button onClick={handleReset}>Reset</button>
  32. </div>
  33. );
  34. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement