import { useEffect } from 'octane';
import { QueryClientContext } from './context.ts';
import type { QueryClientProviderProps } from './types';

// QueryClientProvider — provides the QueryClient via context and mounts/unmounts
// it with the component. It's authored in .tsrx because it's a COMPONENT that
// renders a context Provider with children + a mount effect, which only the
// octane compiler can emit (the binding's hooks stay plain TS).
export function QueryClientProvider(props: QueryClientProviderProps) @{
	useEffect(() => {
		props.client.mount();
		return () => {
			props.client.unmount();
		};
	}, [props.client]);
	<QueryClientContext value={props.client}>{props.children}</QueryClientContext>
}
