import { useState, useEffect } from "react";
import { useDispatch, useSelector } from "react-redux";
import { getAcceptedSlaughterRequest } from "../services/getAcceptedSlaughterRequest";

export const useSlaughterAllocatedRequests = (id) => {
  const dispatch = useDispatch();
  const { acceptedSlaughterRequest } = useSelector((state) => state.fileSlice);
  const [data, setData] = useState(acceptedSlaughterRequest);

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

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

  return data ? data : [];
};
