mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-09 23:15:36 +00:00
refactor: remove react-hotkeys-hook and use inertia propos instead of recreating a local store
This commit is contained in:
25
inertia/hooks/collections/use_active_collection.tsx
Normal file
25
inertia/hooks/collections/use_active_collection.tsx
Normal file
@@ -0,0 +1,25 @@
|
||||
import { PageProps } from '@adonisjs/inertia/types';
|
||||
import { usePage } from '@inertiajs/react';
|
||||
import { CollectionWithLinks } from '~/types/app';
|
||||
|
||||
interface UseActiveCollectionProps {
|
||||
activeCollection?: CollectionWithLinks;
|
||||
}
|
||||
|
||||
export const useActiveCollection = () => {
|
||||
const { props } = usePage<PageProps & UseActiveCollectionProps>();
|
||||
return props.activeCollection;
|
||||
};
|
||||
|
||||
export type WithActiveCollectionProps = {
|
||||
activeCollection?: CollectionWithLinks;
|
||||
};
|
||||
|
||||
export const withActiveCollection = (
|
||||
Component: React.ComponentType<WithActiveCollectionProps>
|
||||
) => {
|
||||
return (props: WithActiveCollectionProps) => {
|
||||
const activeCollection = useActiveCollection();
|
||||
return <Component {...props} activeCollection={activeCollection} />;
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user