refactor: Rename custom hooks for consistency and clarity
Some checks failed
Deploy to Test Environment / deploy-to-test (push) Has been cancelled

This commit is contained in:
2025-12-14 19:32:18 -08:00
parent f9115fdb73
commit d3e546d02f
7 changed files with 28 additions and 14 deletions

View File

@@ -135,10 +135,12 @@ export const AuthProvider: React.FC<{ children: ReactNode }> = ({ children }) =>
* This is what components will use to get auth state and methods.
* It also ensures that it's used within an AuthProvider.
*/
export const useAuth = (): AuthContextType => {
const useAuthHook = (): AuthContextType => {
const context = useContext(AuthContext);
if (context === undefined) {
throw new Error('useAuth must be used within an AuthProvider');
}
return context;
};
};
export { useAuthHook as useAuth };

View File

@@ -40,10 +40,12 @@ export const FlyersProvider: React.FC<{ children: ReactNode }> = ({ children })
return <FlyersContext.Provider value={value}>{children}</FlyersContext.Provider>;
};
export const useFlyers = (): FlyersContextType => {
const useFlyersHook = (): FlyersContextType => {
const context = useContext(FlyersContext);
if (context === undefined) {
throw new Error('useFlyers must be used within a FlyersProvider');
}
return context;
};
};
export { useFlyersHook as useFlyers };

View File

@@ -26,10 +26,12 @@ export const MasterItemsProvider: React.FC<{ children: ReactNode }> = ({ childre
return <MasterItemsContext.Provider value={value}>{children}</MasterItemsContext.Provider>;
};
export const useMasterItems = (): MasterItemsContextType => {
const useMasterItemsHook = (): MasterItemsContextType => {
const context = useContext(MasterItemsContext);
if (context === undefined) {
throw new Error('useMasterItems must be used within a MasterItemsProvider');
}
return context;
};
};
export { useMasterItemsHook as useMasterItems };

View File

@@ -52,10 +52,12 @@ export const ModalProvider: React.FC<{ children: React.ReactNode }> = ({ childre
* The custom hook that components will use to access the modal context.
* It provides a clean and simple API for interacting with modals.
*/
export const useModal = (): ModalContextType => {
const useModalHook = (): ModalContextType => {
const context = useContext(ModalContext);
if (context === undefined) {
throw new Error('useModal must be used within a ModalProvider');
}
return context;
};
};
export { useModalHook as useModal };

View File

@@ -10,7 +10,7 @@ import type { ShoppingList, ShoppingListItem } from '../types';
* A custom hook to manage all state and logic related to shopping lists.
* It encapsulates API calls and state updates for creating, deleting, and modifying lists and their items.
*/
export const useShoppingLists = () => {
const useShoppingListsHook = () => {
const { user } = useAuth();
// We get the lists and the global setter from the DataContext.
const { shoppingLists, setShoppingLists } = useUserData();
@@ -127,4 +127,6 @@ export const useShoppingLists = () => {
isRemovingItem,
error,
};
};
};
export { useShoppingListsHook as useShoppingLists };

View File

@@ -51,10 +51,12 @@ export const UserDataProvider: React.FC<{ children: ReactNode }> = ({ children }
return <UserDataContext.Provider value={value}>{children}</UserDataContext.Provider>;
};
export const useUserData = (): UserDataContextType => {
const useUserDataHook = (): UserDataContextType => {
const context = useContext(UserDataContext);
if (context === undefined) {
throw new Error('useUserData must be used within a UserDataProvider');
}
return context;
};
};
export { useUserDataHook as useUserData };

View File

@@ -10,7 +10,7 @@ import type { MasterGroceryItem } from '../types';
* A custom hook to manage all state and logic related to a user's watched items.
* It encapsulates API calls and state updates for adding and removing items.
*/
export const useWatchedItems = () => {
const useWatchedItemsHook = () => {
const { user } = useAuth();
// Get the watched items and the global setter from the DataContext.
const { watchedItems, setWatchedItems } = useUserData();
@@ -59,4 +59,6 @@ export const useWatchedItems = () => {
removeWatchedItem,
error,
};
};
};
export { useWatchedItemsHook as useWatchedItems };