Skip to content

React Query: Add query factory option #74

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 6 commits into from
Oct 26, 2022

Conversation

adairrr
Copy link
Contributor

@adairrr adairrr commented Oct 20, 2022

This change gives the user the ability to request the use of a "Query Factory" that can be used for (examples using cw20):

  • useQueries
export const useCw20BalancesQueries = ({
  account,
  inputs,
  cw20AddressAccessor,
  options,
} => {
  const { readOnlyClient } = useReadonlyClients()

  const queries = useQueries({
    queries: inputs.map((cw20) =>
      cw20Queries.balance({
        client: readOnlyClient
          ? new Cw20QueryClient(readOnlyClient, cw20AddressAccessor(cw20))
          : undefined,
        args: { address: account },
        options: {
          ...QueryOptions.DISABLE_WITHOUT(readOnlyClient, options?.enabled)
        },
      })
    ),
  })

  return useQueries(queries)
}
  • prefetchQuery (to be placed in cache):
const queryClient = useQueryClient()

queryClient.prefetchQuery(
  cw20Queries.balance({
    client: cw20Client,
    args: { address: 'terra1' },
  })
)

@pyramation
Copy link
Collaborator

woah this is amazing!

Quick Q: is there any new options we should add to the READMEs?

@adairrr
Copy link
Contributor Author

adairrr commented Oct 24, 2022

Yeah you're right! Just added the new queryFactory to the readme.

@pyramation pyramation merged commit 97d14be into hyperweb-io:main Oct 26, 2022
@pyramation
Copy link
Collaborator

merged!!!! @adairrr your work is amazing thank you ⚛️

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.

2 participants