Advertisement
Guest User

Untitled

a guest
Jan 25th, 2023
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function ProfileDetails(props) {
  2.   const dispatch = useDispatch();
  3.   const name = useSelector(selectName);
  4.   const posts = useSelector(selectPostsByAuthor(name));
  5.   const [nameField, setNameField] = useState(true);
  6.  
  7.   return (
  8.     <div>
  9.       <h2>Profile</h2>
  10.      
  11.       <label htmlFor="name">Name: </label>
  12.      
  13.       <input
  14.         id="name" value={name} disabled={nameField}
  15.         onChange={(e) => dispatch(setName(e.target.value))}
  16.       />
  17.  
  18.       <button onClick={() => setNameField(!nameField)}>
  19.         {nameField ? "Change" : "Save"}
  20.       </button>
  21.  
  22.       <p>Posts: {posts.length}</p>
  23.     </div>
  24.   );
  25. }
  26.  
  27. function AppDetails(props) {
  28.   const posts = useSelector(selectPosts);
  29.   const users = useSelector(selectAuthors);
  30.  
  31.   return (
  32.     <div>
  33.       <h2>App</h2>
  34.  
  35.       <p>Users: {users.length}</p>
  36.       <p>Total Posts: {posts.length}</p>
  37.     </div>
  38.   );
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement