Answers for "setting usestate to prop"

0

setting usestate to prop

function Avatar(props) {
  const [user, setUser] = React.useState({...props.user});

  React.useEffect(() => {
      setUser(props.user);
  }, [props.user])

  return user.avatar ? 
         (<img src={user.avatar}/>)
        : (<p>Loading...</p>);
}
Posted by: Guest on May-21-2021

Browse Popular Code Answers by Language