question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

react hooks not using data transformer

See original GitHub issue

I’ve setup my react project according to the docs, but when I use the hooks, it doesn’t seem to use the data transformer.

Here is my trpc setup

import type { Router } from '..'
import superjson from 'superjson'

export const trpc = createReactQueryHooks<Router>()

export const trpcClient = trpc.createClient({
	url: 'http://localhost:8080',
	transformer: superjson,
	headers: () => ({ Authorization: getAuthHeader() }),
})

export const queryClient = new QueryClient({
	defaultOptions: {
		queries: { refetchOnWindowFocus: false, retry: false, refetchOnMount: false },
		mutations: { retry: false },
	},
})

ReactDOM.render(
	<React.StrictMode>
		<trpc.Provider client={trpcClient} queryClient={queryClient}>
			<QueryClientProvider client={queryClient}>
				<App />
			</QueryClientProvider>
		</trpc.Provider>
	</React.StrictMode>,
	document.getElementById('root')
)

And this is how I am using the hooks inside the

const AppHeader: React.FC = () => {
	const { data: school, isLoading } = trpc.useQuery([
		'school.get',
		{ id: schoolId }, //schoolId is a bigint here
	])

	return <></>
}

And i’m getting this error Uncaught TypeError: BigInt value can't be serialized in JSON which shouldn’t happen if the transformer was being called.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
benbaldwin000commented, Jun 13, 2022

just put this together sandbox

1reaction
jlalmescommented, Jun 13, 2022

Excellent @sachinraja! So to be clear the solution is as follows (tested):

const queryClient = new QueryClient({
  defaultOptions: {
    queries: {
      queryKeyHashFn: (queryKey) => {
        return JSON.stringify(superjson.serialize(queryKey))
      },
    },
  },
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Not able to see output of state using react hooks (useState ...
I am able to see the data in console log but nothing seems to be happening when i try to set it to...
Read more >
Loading and Displaying Data with Hooks
In the third article we'll see how to share data between components with React Context without using globals, singletons or resorting to state ......
Read more >
How to Fetch Data From an API Using React Hooks
In this article, we will look at how to fetch data from API using React hooks and also how to use the data...
Read more >
Centralizing state and data handling with React Hooks - Algolia
How to use React Hooks to manage state and data, creating reusable UI components that maintain state information within each component.
Read more >
Using the Effect Hook - React
Hooks are a new addition in React 16.8. They let you use state and other React features without writing a class. The Effect...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found