Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: how to execute code after getting a response? #28

Closed
Guguskis opened this issue Aug 11, 2019 · 3 comments
Closed

Question: how to execute code after getting a response? #28

Guguskis opened this issue Aug 11, 2019 · 3 comments

Comments

@Guguskis
Copy link

I am beginner developer and this might be a dumb question. All I want is to call a function after getting a response.
My current solution is to use useEffect:

useEffect(() => {
    if (!postLoading) {
        // Calling my function
    }
}, [postLoading]);

I don't know if that is a good way or not, but I would prefer to do it something like this:

executePost({
    data: {
        // My data
    }
}).then( /*Calling my function*/);

The second solution in VS Code spits out error "Property 'then' does not exist on type 'void'.".
Is there a way to do this with axios hooks?

@simoneb
Copy link
Owner

simoneb commented Aug 12, 2019

the hooks way would be to use effect, but it should already be possible to await the promise returned by the refetch function. check out this example.

@Guguskis
Copy link
Author

Thank you, this example helped :)

@Lekha30
Copy link

Lekha30 commented Jul 24, 2021

The codesand link above isn't working. I want to do a refetch triggered automatically after a POST.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants