9export const ONLINE_STATUS = {
10 ONLINE: Symbol('ONLINE'),
11 OFFLINE: Symbol('OFFLINE'),
12 UNKNOWN: Symbol('UNKNOWN'),
15const getNetworkState = () => {
16 if ('onLine' in navigator) {
17 return navigator.onLine ? ONLINE_STATUS.ONLINE : ONLINE_STATUS.OFFLINE;
20 return ONLINE_STATUS.UNKNOWN;
23function _useOnline() {
24 const [online, setOnline] = useState(getNetworkState());
27 function handleOnlineStatus(event) {
28 setOnline(getNetworkState());
31 window.addEventListener('online', handleOnlineStatus);
32 window.addEventListener('offline', handleOnlineStatus);
35 window.removeEventListener('online', handleOnlineStatus);
36 window.removeEventListener('offline', handleOnlineStatus);
43const OnlineContext = createContext(null);
46export function OnlineProvider({ children }) {
47 const online = _useOnline();
49 <OnlineContext.Provider value={online}>{children}</OnlineContext.Provider>
54export function useOnline() {
55 return useContext(OnlineContext);
59export const withOnline = Component =>
60 forwardRef((props, ref) => {
62 <OnlineContext.Consumer>
63 {online => <Component ref={ref} online={online} {...props} />}
64 </OnlineContext.Consumer>
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list