Guest User

Untitled

a guest
Dec 12th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. import { useState, useEffect } from 'react';
  2.  
  3. function FriendStatus(props) {
  4. const [isOnline, setIsOnline] = useState(null);
  5.  
  6. function handleStatusChange(status) {
  7. setIsOnline(status.isOnline);
  8. }
  9.  
  10. useEffect(() => {
  11. ChatAPI.subscribeToFriendStatus(props.friend.id, handleStatusChange);
  12.  
  13. return () => {
  14. ChatAPI.unsubscribeFromFriendStatus(props.friend.id, handleStatusChange);
  15. };
  16. });
  17.  
  18. if (isOnline === null) {
  19. return 'Loading...';
  20. }
  21. return isOnline ? 'Online' : 'Offline';
  22. }
Add Comment
Please, Sign In to add comment