Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. import React, { useState } from 'react';
  2.  
  3. const TextVote = () => {
  4. const [votes, setVotes] = useState([
  5. { text: 'OneOneOne', vote: 0 },
  6. { text: 'TwoTwoTwo', vote: 5 },
  7. { text: 'ThreeThreeThree', vote: 0 }
  8. ]);
  9. const votesHandler = () => {
  10. const newClicks = {
  11. ...votes,
  12. vote: votes[1].vote + 1
  13. };
  14. setVotes(newClicks);
  15. };
  16.  
  17. return (
  18. <div className='box'>
  19. <div>{votes[1].text}</div>
  20.  
  21. <div>
  22. <button onClick={votesHandler}>vote</button>
  23. <div>{votes[1].vote}</div>
  24. </div>
  25. </div>
  26. );
  27. };
  28.  
  29. export default TextVote;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement