Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

useeffrc

import React, { useState, useEffect } from 'react';

function FriendStatus(props) {
  const [isOnline, setIsOnline] = useState(null);

  useEffect(() => {
    function handleStatusChange(status) {
      setIsOnline(status.isOnline);
    }
    ChatAPI.subscribeToFriendStatus(props.friend.id, handleStatusChange);
    // Specify how to clean up after this effect:
    return function cleanup() {
      ChatAPI.unsubscribeFromFriendStatus(props.friend.id, handleStatusChange);
    };
  });

  if (isOnline === null) {
    return 'Loading...';
  }
  return isOnline ? 'Online' : 'Offline';
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: enzym.debug 
Javascript :: php vscode editor.rulers vetical line delimiter line 
Javascript :: isag680@hotmail.com 
Javascript :: change active menu item on page scroll javascript 
Javascript :: Assign arrow function to a variable before exporting as module default 
Javascript :: get request send back text 
Javascript :: tab change hash 
Javascript :: finalGrade % 5 && <38 
Javascript :: react proxy to flask server 
Javascript :: merge two array with same length as object 
Javascript :: concatenate strings jsonata 
Javascript :: How to create a debounce higher order function 
Javascript :: javascript promise multi function error 
Javascript :: array.includes is not a function react 
Javascript :: Checking if the first letter of the string is uppercase 
Javascript :: cypress replace response part 
Javascript :: login_page-jwt-auth-using-react-and-flask 
Javascript :: how to make local storage read only site:stackoverflow.com 
Javascript :: New Syntax of Router Routes 
Javascript :: js hk 
Javascript :: react native paper status bar color 
Javascript :: JAVASCRIPT EX. 
Javascript :: Get JSON Values In Array Alternative Syntax 
Javascript :: js rotate matrix as image 
Javascript :: reloading init state 
Javascript :: _.extend Example 
Javascript :: onPlay 
Javascript :: onSeek video getting paused 
Javascript :: js calculate hours between two times 
Javascript :: calcular idade jquery 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =