Skip to content

Header cell with search param setter #5456

Closed Answered by gonstoll
gonstoll asked this question in Q&A
Discussion options

You must be logged in to vote

Well, apparently yesterday was a long day and I was drowning on a glass of water. It's as easy as encapsulating all the search params logic in a component and then just use that component in the header. Final result:

function Filters() {
  const [searchParams, setSearchParams] = useSearchParams()
  const status = searchParams.get('status')

  function handleFilter(status: 'active' | 'inactive') {
    setSearchParams(prev => {
      prev.set('status', status)
      return prev
    })
  }

  return (
    <DropdownMenu>
      <DropdownMenuTrigger>Status</DropdownMenuTrigger>
      <DropdownMenuContent>
        <DropdownMenuLabel>Filter by</DropdownMenuLabel>
        <DropdownMenuSeparator />

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by gonstoll
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant