Skip to content
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

[WIP] feat!: introduce hook for invalidating reads #43

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

achou11
Copy link
Member

@achou11 achou11 commented Jan 22, 2025

Closes #19

proof of concept for how to expose an invalidation helper for reads. i've implemented a useInvalidateRead() hook that accepts a "path" (a unix path-like string) and relevant parameters based on the path. This will mostly be used in cases where something external to core is updated and affects core (a good example is the custom map file import).

function Screen() {
  const importFileMutation = useMutation(...)
  const invalidateRead = useInvalidateRead()
  
  return (
    <Button 
      onPress={() => { 
        importFileMutation.mutate(undefined, {
          onSuccess: () => {
            // Invalidate maps-related queries after file import
            invalidateRead('/maps', undefined)
          }
        })
        
      }}
    >Import file</Button>
  )
}

As of now, the API may be a bit clunky based on preferences. Open to reconsidering.

TODO:

  • finalize API
  • write tests

@achou11 achou11 force-pushed the 19/invalidate-reads-hook branch from e2fd8a3 to eac209b Compare January 22, 2025 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace exported query keys with read hook invalidation helpers
1 participant