Giter VIP home page Giter VIP logo

api's Introduction

api's People

Contributors

dependabot[bot] avatar synvox avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

api's Issues

Is there a way to force refresh?

This is my situation:

In my Create React App I have one page with the a list of form submissions, and a second page with the form itself. Plus a home page.
They are under different React Router routes.

/              # The home page
/submit-visit  # Contains the form to send a new submission
/visits        # Displays a table with the list of submissions

When I open the app on /visits a request is sent ( const visits = api.visits(params);), a spinner shows up (thanks to Suspense), and a little later the submissions fill my table. Here is a pseudocode for the page /visits:

const Visits = () => {
  return (
    <Suspense fallback={<p>Loading...</p>}>
      <List />
    </Suspense>
  );
}

const List = () => {
  const api = useApi();

  // This logs every time I navigate to /visits, so I know for sure that this component
  // is being re-rendered. But only on the first navigation is /api/visits actually called.
  console.log('fetching'); 

  const visits = api.visits();

  return (
    <ul>
      {visits.data.map(visit => <li>{visit.id} {visit.title}</li>)}
    </ul>
  );
}

Now, when the user navigates to /submit-visit and fills and sends the form, upon success he/she is redirected to /visits. But they still see the stale list, no new network request is sent.

What I think happens here is that api sees that I've already called GET /api/visits, reads the cache, and gives me a stale list of submissions. I have to reload the page using the browser button to get the freshly sent form.

How can I force api to refresh even if the request is in the cache?
Maybe touch is what I need? But I can't figure out where I'm supposed to call it... If I call it right after api.visits() am I going to fetch the same route twice on app load?

Does not work with IE11

I'm leaving this here just in case it saves some time to others, not because I expect a fix.

This library makes use of Proxy, which is supported only starting with Edge 12, and is basically non-polyfillable in IE11.

I had a quick look at the source code and it looks like the whole API of this library depends on Proxy. If the author were to make it compatible he would have to basically re-write the whole thing and it wouldn't work the way it works now anyway.

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.