Files
web-menu-react-version-/src/hooks/useRestaurant.ts
Mohammed Al-yaseen cd49a3756f refactor calculation code
- implement fee
- centralize the code
2025-10-27 08:08:22 +03:00

19 lines
555 B
TypeScript

import { updateRestaurant } from "features/order/orderSlice";
import { useEffect } from "react";
import { useAppDispatch } from "redux/hooks";
import { RestaurantDetails } from "utils/types/appTypes";
/**
* Custom hook to automatically load restaurant into Redux store
* when restaurant data is available
*/
export const useRestaurant = (restaurant: RestaurantDetails | undefined) => {
const dispatch = useAppDispatch();
useEffect(() => {
if (restaurant) {
dispatch(updateRestaurant(restaurant));
}
}, [restaurant, dispatch]);
};