SolidJSS
SolidJSโ€ข3y agoโ€ข
2 replies
kerrick

Is this really the most ergonomic way to preserve searchParams with <A>?

I've got what I imagine is a pretty common pattern: displaying a list of entities on the left, each one clickable, and when you click it a detail view shows up on the right. The list is filterable, and those filters end up as searchParams. An example URL might be /locations/123/leads/456?leadsCategory=3. For the anchor tags on the left, I've got the following JSX (searchParams is destructured from useSearchParams()):

<A
  href={`/locations/${
    params.clientId
  }/leads/${
    props.lead.id
  }?${
    new URLSearchParams(searchParams).toString()
  }`}
>


This works, but it feels... unergonomic. Is there a better or cleaner way to preserve the searchParams when using <A /> or is this the "right" way?
Was this page helpful?