Skip to content

onResolve doesn't trigger if response is empty #235

Open
@jargot

Description

@jargot

Hello,

Thanks for the library :)

I'm looking at the useFetch hook and specifically the associated onResolve callback to make a call to my backend and redirect to another URL if the call is successful using this pattern:

let { ... } = useFetch(`${url}`, withAuth(meta, token), {
   defer: true,
   onResolve: data => {
     console.log("Just resolved", data);
     // Redirect will go here
   }
 });

I have absolutely no problem reaching my console.log if I return data in my response in my Express backend like so:

return res.json({
    status: "ok"
});

However, sending an empty 200 response like so:

return res.sendStatus(200);

never triggers the onResolve callback and the console.log is never printed.

Is this the intendend behavior ?

If it is, maybe editing the documentation and mentionning the required data in the response would be helpful.

I'm happy to have a look and PR if needed :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementEnhancement to existing feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions