Use query instead of stae for filter

This commit is contained in:
Sakura Knoll
2022-01-01 18:23:17 +09:00 Unverified
parent fc08656202
commit 06742c5279
4 changed files with 24 additions and 17 deletions
+7 -10
View File
@@ -1,35 +1,32 @@
import { Button } from '@theme-ui/components'
import React, { useCallback } from 'react'
import React from 'react'
import PageLink from './PageLink'
import SquareImageBox from './SquareImageBox'
interface FilterButtonProps {
active?: boolean
icon?: string
label: string
setFilter: (filter: string) => void
value: string
m?: string | number
}
const FilterButton = ({
active = false,
setFilter,
icon,
label,
value,
m,
}: FilterButtonProps) => {
const selectFilter = useCallback(() => {
setFilter(value)
}, [setFilter, value])
return (
<Button
<PageLink
href={{ query: { filter: value } }}
shallow={true}
m={m}
py={1}
px={2}
onClick={selectFilter}
className={active ? 'active' : ''}
sx={{ display: 'flex' }}
variant='buttons.primary'
>
{icon != null && (
<SquareImageBox
@@ -40,7 +37,7 @@ const FilterButton = ({
/>
)}
{label}
</Button>
</PageLink>
)
}
+4 -3
View File
@@ -2,11 +2,12 @@
import NextLink, { LinkProps as NextLinkProps } from 'next/link'
import { Link, LinkProps } from '@theme-ui/components'
type PageLinkProps = LinkProps & NextLinkProps
type PageLinkProps = Omit<LinkProps, 'href'> &
Pick<NextLinkProps, 'href' | 'shallow'>
const PageLink = ({ href, ...otherProps }: PageLinkProps) => {
const PageLink = ({ href, shallow, ...otherProps }: PageLinkProps) => {
return (
<NextLink href={href} passHref={true}>
<NextLink href={href} shallow={shallow} passHref={true}>
<Link {...otherProps} />
</NextLink>
)