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

useQuery throws an error saying useQuery isn't exported when using in a custom hook #2478

Open
NotoriousGOR opened this issue Feb 9, 2023 · 2 comments

Comments

@NotoriousGOR
Copy link

What is the location of your example repository?

No response

What version of Hydrogen are you using?

^1.5.0

What version of Remix are you using?

No response

Steps to Reproduce

So, I am using Oxygen as my hosting platform.

  1. Create a custom hook that uses useQuery for a 3rd party API. Specifically, I'm using it like this:
export function useGetBuilderContent(model: string, queryName: string) {
  const {data} = Shopify.useQuery(queryName, async () => {
    return await builder
      .get(model)
      .promise()
      .then(({data}) => data);
  });

  return data;
}
  1. Use the new custom hook in an SSR component
  2. Run yarn build or the equivalent for your package manager

The only way to fix it, for now, is to change the import statement from:
import {useQuery, useServerProps} from '@shopify/hydrogen';

To:
import * as Shopify from '@shopify/hydrogen';

Expected Behavior

It's bundled as expected and succeeds in the build process.

Actual Behavior

Fails with an error message:

'useQuery' is not exported by node_modules/@shopify/hydrogen/dist/esnext/client.js, imported by src/lib/hooks.ts

@jplhomer
Copy link
Contributor

jplhomer commented Feb 9, 2023

👋 This looks like a Hydrogen v1 issue. useQuery etc are no longer part of Hydrogen 2023.1, which was released today. I'm going to transfer your issue to the correct repo.

@jplhomer jplhomer transferred this issue from Shopify/hydrogen Feb 9, 2023
@NotoriousGOR
Copy link
Author

👋 This looks like a Hydrogen v1 issue. useQuery etc are no longer part of Hydrogen 2023.1, which was released today. I'm going to transfer your issue to the correct repo.

Thank you and congrats @jplhomer + Shopify!

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

No branches or pull requests

2 participants