-
Notifications
You must be signed in to change notification settings - Fork 3
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
Re-render when one item in collection is updated. #102
Comments
I have found a solution :
Any remarks ? |
It doesn't work as expected, internalState in the 'on' hook is always empty |
Hi Gwen, The normal way to solve this that you use So to rewrite your original example: function MyCollection() {
const { items, loading } = useCollection(
res.follow('collection', {
from: currentMonth.toISOString(),
to: currentMonth.toISOString(),
}),
// Note that 'items' instead of 'item' is less common, so you might prefer to
// rename this rel.
{ rel: 'items', refreshOnStale: true }
);
if (loading) return 'Loading...';
return items.map(item => <MyItem key={item.url} resource={item});
}
function MyItem(props: {resource: Resource}) {
const { data, loading } = useResource(resource);
if (loading) return 'Loading...';
return <>data.code</>;
} The reason the event for changing resources is not changing the top-level, is because changes in the collection do not extend to 'embedded items'. Changes in the event only really apply to propertes on the collection itself, or membership changes (adding or removing item from collection), but not the state of the members themselves. I do think having a hook like |
Yes I thought of this solution but it may not apply in some cases. I also use react-table, and similarly, if an item in the list changes, I need to be able to refresh it. I have improved the proposed code in this way:
|
That does make sense. The server-side way to handle this, is if you did a
This basically lets a server say: "We completed the PUT request, the client should also be aware that the cache for the parent collection is also stale. If the server does this, Ketting will fire all the right events and re-renders. Would that solve your problem? |
I have a similar mechanism to invalidate the cache but that's not what I want. Having failed to get by on this case and on other cases with react-ketting, I used ketting by developing my own hooks to chain the calls... |
Hello !
I use the hook useCollection with an Hypermedia API (HAL) and i have problems with ketting cache.
I have an endpoint who returns a JSON like
And i use useCollection like this :
When I perform certain actions on another component, ketting cache of one item in the previous list is updated, but the component that call the useCollection doesn't refresh (and the s.code remains the same).
Did I misunderstand something?
The text was updated successfully, but these errors were encountered: