UNPKG

@trpc/next

Version:

The tRPC Next.js library

40 lines (36 loc) 1.36 kB
'use strict'; var shared = require('@trpc/react-query/shared'); var unstableCoreDoNotImport = require('@trpc/server/unstable-core-do-not-import'); var React = require('react'); var withTRPC = require('./withTRPC.js'); /* istanbul ignore file -- @preserve */ // We're testing this through E2E-testing function createTRPCNext(opts) { const hooks = shared.createRootHooks(opts); // TODO: maybe set TSSRContext to `never` when using `WithTRPCNoSSROptions` const _withTRPC = withTRPC.withTRPC(opts); const proxy = shared.createReactDecoration(hooks); return unstableCoreDoNotImport.createFlatProxy((key)=>{ if (key === 'useContext' || key === 'useUtils') { return ()=>{ const context = hooks.useUtils(); // create a stable reference of the utils context return React.useMemo(()=>{ return shared.createReactQueryUtils(context); }, [ context ]); }; } if (key === 'useQueries') { return hooks.useQueries; } if (key === 'useSuspenseQueries') { return hooks.useSuspenseQueries; } if (key === 'withTRPC') { return _withTRPC; } return proxy[key]; }); } exports.createTRPCNext = createTRPCNext;