Replies: 2 comments
-
You can set the headers for the fetch method as explained here: https://javascript.info/fetch-api |
Beta Was this translation helpful? Give feedback.
0 replies
-
I would say the stores API is treating the So I'd say RN is behaving correctly and the shops API is not. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello all,
I have a component that fetches some
orders
from an API, and refetches them whenever a user returns to a page (users can also pull to refresh). If a new order is added and a user returns to the<OrderList />
page, then I'd expect the new order to appear after the GET call is made.The problem is that React Native's
fetch
is automatically adding theif-modified-since
header whenever users return to the page, so the response returned from ourfetcher
contains only the newly added order. I'm surprised thatfetch
automatically adds theif-modified-since
header by default, and I'm wondering how this situation would normally be handled withuseSWR
. Is this a problem people often run into?I think that
useSWR
is completely removed from the HTTP cache and maintains its owncache
. I think the ideal behavior would be that theif-modified-since
header is added, the GET call returns only the newly added order, and then somehow that new order is merged with the previously fetched orders, so that<OrderList />
displays all orders.I found a workaround by setting
cache-control: 'no-store'
on thefetcher
, but then we lose all benefits of HTTP caching anduseSWR
's cache. How should I go about handling this?Beta Was this translation helpful? Give feedback.
All reactions