mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-08 22:53:25 +00:00
26 lines
752 B
TypeScript
26 lines
752 B
TypeScript
import { PageProps } from '@adonisjs/inertia/types';
|
|
import { usePage } from '@inertiajs/react';
|
|
import { CollectionWithLinks } from '~/types/app';
|
|
|
|
interface UseCollectionsProps {
|
|
collections: CollectionWithLinks[];
|
|
}
|
|
|
|
export const useCollections = () => {
|
|
const { props } = usePage<PageProps & UseCollectionsProps>();
|
|
return props.collections;
|
|
};
|
|
|
|
export type WithCollectionsProps = {
|
|
collections: CollectionWithLinks[];
|
|
};
|
|
|
|
export const withCollections = <T extends object>(
|
|
Component: React.ComponentType<T & WithCollectionsProps>
|
|
): React.ComponentType<Omit<T, 'collections'>> => {
|
|
return (props: Omit<T, 'collections'>) => {
|
|
const collections = useCollections();
|
|
return <Component {...(props as T)} collections={collections} />;
|
|
};
|
|
};
|