Caching
Unanswered
Brown bear posted this in #help-forum
Brown bearOP
Hey Guys - Semi Newbie here.
I am creating a Request through an API however, since the API has a API limit, i only want to req it once and use the response throughout. Specifically, only a property within the returned object. By reading the docs, I see the return can be memoized or cached however I am unable to do so.
Can someone explain the logic of this. Meaning, I send a req, then it gets stored in the cache then it can be used unversially in all components ?
How can i be sure the req is not sent again ?
I am creating a Request through an API however, since the API has a API limit, i only want to req it once and use the response throughout. Specifically, only a property within the returned object. By reading the docs, I see the return can be memoized or cached however I am unable to do so.
Can someone explain the logic of this. Meaning, I send a req, then it gets stored in the cache then it can be used unversially in all components ?
How can i be sure the req is not sent again ?
1 Reply
Black carp
You need to embed your caching logic into your data fetching logic. Libraries such as react-query (now called tan-query) and SWR are precisely meant for this use case.