-
Notifications
You must be signed in to change notification settings - Fork 286
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
Fixes to <VariantSelector>
API and add useVariantUrl
hook
#1094
Conversation
We detected some changes in |
25795e4
to
6ab6096
Compare
<VariantSelector>
API and add useVariantUrl
hook
@@ -19,7 +19,8 @@ | |||
"version:hydrogen": "node -p \"'export const LIB_VERSION = \\'' + require('./packages/hydrogen/package.json').version + '\\';'\" > packages/hydrogen/src/version.ts", | |||
"version:cli": "cd packages/cli && npm run generate:manifest", | |||
"changeset": "changeset", | |||
"clean-all": "rimraf node_modules/.bin && rimraf node_modules/.cache && rimraf packages/*/dist && rimraf templates/*/.cache" | |||
"clean-all": "rimraf node_modules/.bin && rimraf node_modules/.cache && rimraf packages/*/dist && rimraf templates/*/.cache", | |||
"check": "npm run build && npm run lint && npm run typecheck && npm run test" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I run all of these before commit. So figured I'd add a simple check command.
import {useVariantUrl} from '@shopify/hydrogen'; | ||
|
||
function MyComponent() { | ||
const {to, search} = useVariantUrl('snowboard', [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't return a real URL
object, because we don't easily have the origin at the moment, because useLocation()
doesn't return it. I felt like path
or pathname
implies it doesn't include the search
(because the native URL.prototype.pathname
doesn't).
Fixes to
<VariantSelector>
API and adduseVariantUrl
hook.<VariantSelector>
now takeshandle
as a property. This makes the component useable on pages other than the default PDP route.<VariantSelector>
also gives you the product options search param, so if you have a custom PDP route, you can still link to it.useVariantUrl
is useful for situations where you want to get a link to a product variant.WHY are these changes introduced?
Fixes #0000
WHAT is this pull request doing?
HOW to test your changes?
Post-merge steps
Checklist