rsm-hcd / AndcultureCode.JavaScript.React

Common patterns, functions, etc... used when building react applications
6 stars 8 forks source link

Add useNetworkInformation hook #65

Open myty opened 3 years ago

myty commented 3 years ago

This would return the NetworkInformation interface from this: https://github.com/AndcultureCode/AndcultureCode.JavaScript.Core/issues/101

Proposed hook could look something like this:


const useNetworkInformation = (): NetworkState => {
    const [networkState, setNetworkState] = useState<NetworkState>({
        isOnline: true,
    });

   useEffect(() => {  /* add and remove connection change handler */ }, []);

    return {
      ...networkState
    }
};