Skip to content
This repository was archived by the owner on Apr 2, 2024. It is now read-only.
This repository was archived by the owner on Apr 2, 2024. It is now read-only.

Question: notify components of cache change #3

@stevewillard

Description

@stevewillard

Thank you for the great library!

I have a question around a more complex, but probably common use case of multiple use-fetch hooks in a component tree. Maybe you have run into this before.

Suppose you have a todo app, where the header contains a count of open todos. This count comes from a use-fetch hook /api/todos and looks at the resulting data.length. There's a child component which renders a list of the todos using the same API, but a different hook. If I close one of the open todos in the list, and refetch, the list will update, but the count will be stale, even though the hooks read from the same caching key. At least, I believe that is true?

Do you have any recommendations for notifying the parent component that the cache is updated? The simplest approach would be to pass down the doFetch from the parent to child. But, this gets pretty messy if there's lots of nesting. It gets even more complicated if the API that has the count is different than the one which has the list.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions