#Any example of serializeable class to be used in Qwik?

2 messages · Page 1 of 1 (latest)

night shell
#

My app usually operates with plain javascript objects, but sometimes it has to throw errors. I widely use stores with useContextProvider / useContext, and

const store = useContext(SOME_STORE) // store.data can be either a plain javascript object or a CustomError('something')

Qwik complains about the store:
Seems like you are referencing "store" inside a different scope (useTask$), when this happens, Qwik needs to serialize the value, however, "store.value.data" is an instance of the "CustomError" class, which is not serializable. Use a simple object literal instead.

What should I add to the definition of CustomError class so that it becomes serializable? It already has toJSON method.

Is there any example of a custom serializable class that is supported by Qwik?

wooden hearth
#

There's no custom serializers in Qwik, mostly to keep resuming fast.
So you have to extract the information from your custom error and store it as separate fields