Skip to content

Elaborate Immediate Mutation Updates / Create section #358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ghost opened this issue Jun 11, 2020 · 5 comments
Closed

Elaborate Immediate Mutation Updates / Create section #358

ghost opened this issue Jun 11, 2020 · 5 comments
Labels
enhancement New feature or request

Comments

@ghost
Copy link

ghost commented Jun 11, 2020

Is your feature request related to a problem? Please describe.
I was working on a project where I needed to trigger re-fetching the list of resource instances (e.g. order items) and force-update of all the components displaying such a list in cases when a) the new resource instance was created and b) some other resource instance (e.g. account preference) changed.

I've tried to follow the instructions given in the Immediate Mutation Updates (update and create sections), but didn't manage to come up with a reliable solution, most likely because of misuse and misunderstanding of the APIs.

Describe the solution you'd like
It would be great to have more elaborated documentation that would show examples of how to properly trigger re-fetching of the list of resources once a new instance is created, and also do so once some other resource changed.

Could it be done using useInvalidator()?

Describe alternatives you've considered
Add a section that outlines some common usage patterns.

@ghost ghost added the enhancement New feature or request label Jun 11, 2020
@ntucker
Copy link
Collaborator

ntucker commented Jun 12, 2020

Imperatively refetching can be done with https://resthooks.io/docs/api/useFetcher

For adding a new item to a list, you won't have to wait on the refetch if you use https://resthooks.io/docs/api/useFetcher#updateparams-destshape-destparams-updatefunction - tho admittedly that's a bit more finessing to get right.

@ghost
Copy link
Author

ghost commented Jun 12, 2020

@ntucker thanks for the links! I've actually tried to use updateParams - but for some reason that didn't work for my case. In my situation I specifically needed to refetch the list as the single change affected the presentation of each of the entities in the list returned from the server.

@sudo-something
Copy link

I'm having the same problem with respect to updating a child array. Despite using .asSchema() as described here, when an item in the child array is deleted or a new child item added, subsequent renders of the parent item do not reflect the updated children. It appears the child object pk's are cached and not getting invalidated on executing a fetch using a delete or update shape based. I'm observing this when I delete a child item and navigate to a page rendering the parent item. This will throw an exception on attempting to get the child from cache and it's not present.

I'm with @dair-targ... I'm either using the API wrong and the docs could use some clarity on this scenario or there's a bug in the cache provider.

@ntucker
Copy link
Collaborator

ntucker commented Jul 12, 2020

@smith-it Try the latest 5 release. It includes #360 which makes deletes behave in a more predictable way. It should cause any schema trying to use them still to suspend so they can be accurate.

@dair-targ Seems unavoidable to imperatively fetch via usefetcher then. useInvalidator could be used if you want to suspend instead of just fetch in background. (be sure to use latest 5 release to have this behavior work in predictable way)

@ntucker
Copy link
Collaborator

ntucker commented Apr 17, 2021

#760 allows for full entity changes rather than just primary keys. Tracking this in new design there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants