@preact-signals/query
Version:
A reactive utility for React/Preact that simplifies the handling of data fetching and state management. Powered by Preact Signals, it provides hooks and functions to create reactive resources and manage their state seamlessly.
23 lines • 917 B
JavaScript
'use client';
import * as React from 'react';
import { hydrate } from '@tanstack/query-core';
import { useQueryClient } from './QueryClientProvider';
export function useHydrate(state, options = {}) {
const queryClient = useQueryClient({ context: options.context });
const optionsRef = React.useRef(options);
optionsRef.current = options;
// Running hydrate again with the same queries is safe,
// it wont overwrite or initialize existing queries,
// relying on useMemo here is only a performance optimization.
// hydrate can and should be run *during* render here for SSR to work properly
React.useMemo(() => {
if (state) {
hydrate(queryClient, state, optionsRef.current);
}
}, [queryClient, state]);
}
export const Hydrate = ({ children, options, state }) => {
useHydrate(state, options);
return children;
};
//# sourceMappingURL=Hydrate.js.map