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

Add Mechanism to Refetch in createMutatorStore Without a Loading State #25

Open
martinmckenna opened this issue Jan 29, 2024 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@martinmckenna
Copy link
Contributor

martinmckenna commented Jan 29, 2024

Hi I have a use case like this:

const queryKey = "things"

export const $things = createFetcherStore(queryKey, {
      fetcher: () =>
        getThings().then((response) => response.data),
    })

export const $createThing = createMutatorStore<Payload>(async ({ data, invalidate }) => {
  invalidate(queryKey);
  return createThing(payload);
});

I would really like a way for createMutatorStore to be able to call invalidate to trigger a refetch but without setting $things.loading back to true. I want it to replace the old data with the new data but do it without clearing everything out before because it's fine to show stale data until the new stuff comes back

Either that, or expose a refetch callback on the createFetcherStore return value, so that we can call it from the react component

This seems pretty standard in libraries like react query

@martinmckenna
Copy link
Contributor Author

ah nvm I guess you can just say if (!data && loading) as the condition for first load

@dkzlv
Copy link
Member

dkzlv commented Jan 30, 2024

@martinmckenna Yep, you guessed it right! I suppose, it'd be better to update the README to reflect a better approach then if (loading) return <>loading</>. I already use a different approach in all my SB demos.

@dkzlv dkzlv added the documentation Improvements or additions to documentation label Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants