Skip to content

Commit

Permalink
Updated modals to use local state rather than URL state due to scolli…
Browse files Browse the repository at this point in the history
…ng issue with the latest useRouter.

See: vercel/next.js#49087
  • Loading branch information
BarnabyBishop committed May 18, 2023
1 parent 70e84c8 commit 33ede42
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions docs/src/components/templates.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use client';

import { useRouter, useSearchParams } from 'next/navigation';
import Image, { StaticImageData } from 'next/image';

import {
Expand Down Expand Up @@ -122,19 +121,14 @@ function useLastTruthyValue<T>(val: T): T {
}

export default function Templates() {
const router = useRouter();
const searchParams = useSearchParams();
const template = searchParams?.get('template');
const [currentTemplateId, setCurrentTemplateId] = useState('');

const templateMatch = templates.find(t => t.id === template);
const templateMatch = templates.find(t => t.id === currentTemplateId);

const lastTemplate = useLastTruthyValue(templateMatch);

const onClose = () => {
// Remove the template search param
const queryParams = new URLSearchParams(searchParams || '');
queryParams.delete('template');
router.push(`/?${queryParams}`);
setCurrentTemplateId('');
};

return (
Expand Down Expand Up @@ -177,11 +171,7 @@ export default function Templates() {

<CtaButtons
template={template}
onClick={() => {
const params = new URLSearchParams(searchParams || '');
params.append('template', template.id);
router.push(`/?${params}`);
}}
onClick={() => setCurrentTemplateId(template.id)}
/>
</div>
</div>
Expand Down

0 comments on commit 33ede42

Please sign in to comment.