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

fix(bridge-gatsby): trigger a render on search params load #1515

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions packages/npm/@amazeelabs/bridge-gatsby/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
} from '@amazeelabs/bridge';
import { useLocation as gatsbyUseLocation } from '@reach/router';
import { Link as GatsbyLink, navigate as gatsbyNavigate } from 'gatsby';
import React, { ComponentProps } from 'react';
import React, { ComponentProps, useEffect } from 'react';

export const Link: LinkType &
Pick<ComponentProps<typeof GatsbyLink>, 'ref'> = ({ href, ...props }) => {
Expand All @@ -14,12 +14,21 @@ export const Link: LinkType &

export const useLocation: useLocationType = () => {
const location = gatsbyUseLocation();
const [updatedSearch, setUpdatedSearch] = React.useState('');
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the search enough? What about the query fragment, can we test if that works correctly?
Otherwise we maybe should store the whole url object in the state?

useEffect(() => {
if (location.search) setUpdatedSearch(location.search);
}, [location.search]);

return [
new URL(location.href || location.pathname, 'relative:/'),
{
...location,
search: updatedSearch,
searchParams: new URLSearchParams(updatedSearch),
},
gatsbyNavigate,
];
};

export const LocationProvider: LocationProviderType = ({ children }) => {
return <>{children}</>;
};
};
Loading