import { useDispatch, useSelector } from 'react-redux';
import { fetchApps } from '../redux/actions';
import { getApps } from '../redux';
import { getAppById, getAppslLoading } from '../redux/selectors';

export function useApps() {
  const dispatch = useDispatch();
  const apps = useSelector(getApps);
  const app = useSelector(getAppById);
  const appTableLoading = useSelector(getAppslLoading);

  function loadApps() {
    return dispatch(fetchApps());
  }

  return {
    apps,
    app,
    loadApps,
    appTableLoading,
  };
}
