Git Product home page Git Product logo

Comments (4)

ryanbrainard avatar ryanbrainard commented on May 28, 2024 1

The closest you can get to doing that is using the withRef option and then tacking on an andThen to the request to call methods on the component; however, I'd recommend just handling it in componentDidUpdate.

from react-refetch.

StudioSpindle avatar StudioSpindle commented on May 28, 2024

Might have found it.

The handleResponse: function (response) {} can be used, as described under setting defaults and hooking into internal processing

from react-refetch.

ryanbrainard avatar ryanbrainard commented on May 28, 2024

Instead of trying to call a callback or do anything like that in render(), I recommend using the componentDidUpdate() hook to act upon changes to settingsPutResponse. Something like:

  componentDidUpdate() {
    if (settingsPutResponse && settingsPutResponse.fulfilled) {
      resetForm();
      setSubmitting(false);
    }
  }

However, resetForm() and setSubmitting(false) should probably be an atomic update to avoid partial state changes.

Better yet, don't even reset your form, but instead, just re-mount it. A cheap way to do that is to wrap it in a container element that has a key attribute that changes.

I would strongly recommend not using handleResponse to accomplish this. It sounds like you're trying to treat a PromiseState as a Promise, but they are not the same thing. Remember, your component is rendering the state of the promise at a point in time, so a callback doesn't really make sense on something that will be re-rendered many times over.

from react-refetch.

StudioSpindle avatar StudioSpindle commented on May 28, 2024

Thanks for the feedback. Indeed handleResponse is not correct.

In general, is there no way to handle the response of the fetch as similar to the code examples given?

i.e.

settingsPut(true, (response) => {
//...

// or 
settingsPut(true).then((response) => {
// ...

Would that go against the principles of react-refetch or perhaps be a feature request

from react-refetch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.