import React, { useContext, createContext } from 'react';
import { useNetInfo } from '@react-native-community/netinfo';

import { NetInfoState } from '@react-native-community/netinfo';

const ConnectionContext = createContext<NetInfoState | null>(null);

export const ConnectionProvider = ({ children }: { children: React.ReactNode }) => {
  const netInfo = useNetInfo();

  return <ConnectionContext.Provider value={netInfo}>{children}</ConnectionContext.Provider>;
};

export const useConnection = () => useContext(ConnectionContext);
