{"version":3,"file":"reuseQuery.cjs","names":["useReactiveRender"],"sources":["../../../../src/api/hooks/reuseQuery/reuseQuery.ts"],"sourcesContent":["import { useReactiveRender } from '../utils';\n\n/**\n * Reuses a tools reactive query-like state inside React.\n *\n * `createState` is called only once, during the first React render. The\n * resulting reactive object is passed to `useReactiveRender`, which derives the\n * observed dependencies by mapping the fields of that first state object. When\n * any observed reactive field changes, React is forced to render again.\n *\n * This is useful for composing custom React query hooks from the core\n * `@pastweb/tools` API hooks without rewriting their state machines. Use\n * {@link reuseMutation} as a semantic alias when the reused state represents a\n * mutation rather than a query.\n *\n * @typeParam TState - Reactive state object returned by the core hook.\n * @param createState - Factory that creates the tools reactive state once.\n * @returns The same reactive state object, connected to React rendering.\n *\n * @example\n * ```tsx\n * import { useQuery as createToolsQuery } from '@pastweb/tools';\n * import { reuseQuery } from '@pastweb/react';\n *\n * function useUsers(agent: Agent) {\n *   return reuseQuery(() => createToolsQuery({\n *     fn: () => agent.get('/api/users', { queryKey: ['users'] }),\n *   }));\n * }\n * ```\n */\nexport function reuseQuery<TState extends Record<PropertyKey, any>>(\n  createState: () => TState,\n): TState {\n  return useReactiveRender(createState);\n}\n\n/**\n * Semantic alias for {@link reuseQuery} when reusing a tools mutation-like\n * reactive state inside React.\n *\n * It uses the exact same implementation as `reuseQuery`; the separate name is\n * only for clearer custom hook code.\n *\n * @typeParam TState - Reactive mutation state object returned by the core hook.\n * @param createState - Factory that creates the tools reactive state once.\n * @returns The same reactive state object, connected to React rendering.\n *\n * @example\n * ```tsx\n * import { useMutation as createToolsMutation } from '@pastweb/tools';\n * import { reuseMutation } from '@pastweb/react';\n *\n * function useSaveUser(agent: Agent) {\n *   return reuseMutation(() => createToolsMutation({\n *     fn: user => agent.post('/api/users', user),\n *   }));\n * }\n * ```\n */\nexport const reuseMutation = reuseQuery;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,SAAgB,WACd,aACQ;CACR,OAAOA,0CAAAA,kBAAkB,WAAW;AACtC;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,MAAa,gBAAgB"}