contiamo / restful-react

A consistent, declarative way of interacting with RESTful backends, featuring code-generation from Swagger and OpenAPI specs 🔥
MIT License
1.87k stars 109 forks source link

Changes to requestOptions do not trigger refetch #272

Closed seanlaff closed 4 years ago

seanlaff commented 4 years ago

We use requestOptions to set headers for authorization and tenancy info, but refetches do not get triggered when requestOptions changes, leading to stale state.

There is no check for comparing the previous vs new requestOptions like there is for resolve. https://github.com/contiamo/restful-react/blob/61604ee50626b3c910224225cf4dd92cf4b260b0/src/Get.tsx#L191-L205

fabien0102 commented 4 years ago

Indeed, nice catch, do you want to take care of this?

seanlaff commented 4 years ago

Sure, although I have a little concern over what this means for users that have built against the old behavior. If I follow the example of resolve, folks will need to be very cognizant of memoizing the requestOptions func. Does that sound ok @fabien0102 ?

fabien0102 commented 4 years ago

Sounds good, and don't worry for compatibilty, I don't mind bumping the major version if it's to improve the library (and stay safe about versionning) 😉

For the memoization, I don't have better solution, but if you are working with react and hooks, this little useMemo is quite a mandatory knowledge at some point 😁

seanlaff commented 4 years ago

Sounds good!