Skip to content

feat: deferred queries in loader #8

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

Merged
merged 2 commits into from
Jan 18, 2023
Merged

Conversation

imp-dance
Copy link
Collaborator

@imp-dance imp-dance commented Jan 18, 2023

Deferring queries

You can defer queries by using the deferredQueries argument in createLoader (or createUseLoader). These queries are passed as the second argument to transform which has to be used to access the deferred queries in your loaded component.

Example usage:

const loader = createLoader({
  queries: () => [useImportantQuery()] as const,
  deferredQueries: () => [useSlowButNotImportantQuery()] as const,
  transform: (queries, deferredQueries) => ({
    important: queries[0].data,
    not_important: deferredQueries[0].data,
  }),
});
const Component = withLoader((props, loaderData) => {
  const { important, not_important } = loaderData;
  // not_important could be undefined
  return (
    <div>
      {important.person.name}
      {not_important ? "it has resolved : "some fallback"}
    </div>
  )
}, loader);

Copy link
Collaborator Author

@imp-dance imp-dance left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

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.

1 participant