import { useState, useEffect } from "react";
import { useDispatch, useSelector } from "react-redux";
import { getProvinceNewRequests } from "../services/get-province-new-requests";

const useProvinceRequests = () => {
  const [data, setData] = useState(null);
  const dispatch = useDispatch();
  const defaultValue = useSelector(
    (state) => state.provinceSlice.provinceNewRequests
  );

  useEffect(() => {
    dispatch(getProvinceNewRequests());
  }, []);

  useEffect(() => {
    setData(defaultValue);
  }, [defaultValue]);

  return data ? data : [];
};

export default useProvinceRequests;
