class ObjectHasher {
static referenceToHash = new WeakMap()
static getHash(obj: any) {
const found = this.referenceToHash.get(obj)
if (found) return found
const hash = randomString()
this.referenceToHash.set(obj, hash)
return hash
}
static getReference(hash: string) {
return this.referenceToHash.get(hash)
}
}
function App() {
const {} = useQuery({
queryKey: [userId, ObjectHasher.getHash(largeObject)] as const, // <-- this turns into a string
queryFn: ctx => {
const [userId, hash] = ctx.queryKey
const reference = ObjectHasher.getReference(hash) // <-- then I get it back later
...
},
})
}
class ObjectHasher {
static referenceToHash = new WeakMap()
static getHash(obj: any) {
const found = this.referenceToHash.get(obj)
if (found) return found
const hash = randomString()
this.referenceToHash.set(obj, hash)
return hash
}
static getReference(hash: string) {
return this.referenceToHash.get(hash)
}
}
function App() {
const {} = useQuery({
queryKey: [userId, ObjectHasher.getHash(largeObject)] as const, // <-- this turns into a string
queryFn: ctx => {
const [userId, hash] = ctx.queryKey
const reference = ObjectHasher.getReference(hash) // <-- then I get it back later
...
},
})
}