PMDL
I want to instanciate incoming data using useFetch(), should I use transform or onResponse()?
I'm still not entirely sure why that problem arises tbh, where that wasn't a problem without using transform. My understanding of nuxt lifecycle is not yet optimal.
24 replies
I want to instanciate incoming data using useFetch(), should I use transform or onResponse()?
To reply that: If I use
const { data } = useFetch('/users')
and build some kind of computed ref over data to instantiate data.value
using UserModel. And that works but it's very repetitive to do it for every call we have.
Instead I could make const { data } = customUseFetch('/users', UserModel)
where customUseFetch
transforms the received data, instantiating it with the provided model (original question). That's nice but now I get the dreaded ERROR [nuxt] [request error] [unhandled] [500] Cannot stringify arbitrary non-POJOs
at hydration stage.24 replies
I want to instanciate incoming data using useFetch(), should I use transform or onResponse()?
I have a models/ folder with TS files like users.ts where my classes are. There could be several of those in the same file (class User, class UserStats, class UserProfile, ...), all named exported. As far as I can tell no other exports than those classes that could all be needed to serialise / deserialise. So I guess yes I could traverse that dir? I could try that, but it feels hacky.
24 replies
I want to instanciate incoming data using useFetch(), should I use transform or onResponse()?
Is there a way for that plugin to "discover" the classes in my "classes/*ts" folder, import them all, and make the map itself? I'm asking that because I come from python, not javascript, I don't know if that is easy doable.
24 replies
I want to instanciate incoming data using useFetch(), should I use transform or onResponse()?
Hi @Cue ! Thanks, yes this is precisely my solution, but I still need to manually add any new class I add to my code to that plugin after I receive an error when developing.
24 replies
I want to instanciate incoming data using useFetch(), should I use transform or onResponse()?
Hi! It's been a while since that question, I had actually forgot I asked it. So yes, the transform way works to a point (my data is instantiated and reactive), but now I need to register a reducer / reviver couple for each Model, which is cumbersome:
24 replies
I want to instanciate incoming data using useFetch(), should I use transform or onResponse()?
Ok thanks! Using SSR, we have a serialization/deserialization logic using reducers and revivers and the same
class-transformer
module. That works well!24 replies