Advertisement
Guest User

Untitled

a guest
Jan 25th, 2023
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function PostsSection(props) {
  2.   const dispatch = useDispatch();
  3.   const name = useSelector(selectName);
  4.   const [text, setText] = useState('');
  5.  
  6.   const handleClick = (e) => {
  7.     e.preventDefault();
  8.     if(text !== '') {
  9.       dispatch(createPost({
  10.         author: name,
  11.         text: text
  12.       }));
  13.       setText('');
  14.     }
  15.   };
  16.  
  17.   return (
  18.     <div>
  19.       <div>
  20.         <textarea
  21.           value={text}
  22.           onChange={(e) => setText(e.target.value)}  
  23.         />
  24.         <button onClick={handleClick}>Post</button>
  25.       </div>
  26.     </div>
  27.   );
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement