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

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

  useEffect(() => {
    dispatch(getSlaughterHousesRequest({ key: id }));
  }, []);

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

  return data ? data : [];
};

export default useSlaughterHousesRequest;
