Reference:
This code: electron-trpc demo
I’ve created a corresponding demo: electron-10-demo-etrpc. My aim is to place the created trpcReact
instance in a common location so that all components can import and use it. Here is the code:
import { createTRPCReact } from '@trpc/react-query';
import type { AppRouter } from '../../main/api';
export const trpcReact = createTRPCReact<AppRouter>();
However, when running it, an error occurs:
Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM).
2. You might be breaking the Rules of Hooks.
3. You might have more than one copy of React in the same app.
I suspect that the line of code
export const trpcReact = createTRPCReact<AppRouter>();
cannot be written outside of a functional component. So, I’m wondering if there are other ways to achieve creating it in one place and then having all components be able to import and use it?