🎥 Video | YoutubeGoogle Ads: What if you could 10x your ad creative?(09.09.2026 um 23:39 Uhr)
🎥 Video | YoutubeHow to link your Google Ads manager account to a payments profile(10.09.2026 um 14:14 Uhr)
🎥 Video | YoutubeGoogle Ads: PMax for store goals: Boost in-store sales(10.09.2026 um 14:24 Uhr)
🎥 Video | YoutubeGoogle Ads: How to build a modern measurement stack(10.09.2026 um 17:46 Uhr)
🎥 Video | YoutubeGoogle Ads: What if you could 10x your ad creative?(09.09.2026 um 23:39 Uhr)
🎥 Video | YoutubeHow to link your Google Ads manager account to a payments profile(10.09.2026 um 14:14 Uhr)
🎥 Video | YoutubeGoogle Ads: PMax for store goals: Boost in-store sales(10.09.2026 um 14:24 Uhr)
🎥 Video | YoutubeGoogle Ads: How to build a modern measurement stack(10.09.2026 um 17:46 Uhr)

🔧 Programmierung 🕛 vor 1 Jahr 8 Min Lesezeit
0

Building a Library to Sync TanStack Table State with URL Parameters

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

/

state with URL search params.






tanstack-table-search-params.mp4








🚀 Quick Start




First, install the package.



npm i tanstack-table-search-params



For example, if you are using Next.js (Pages Router), you can use the hook like this.



import { useReactTable } from "tanstack-table";
import { useRouter } from "next/router";
import { useTableSearchParams } from "tanstack-table-search-params";
const router = useRouter();

// Get state and onChanges
const stateAndOnChanges = useTableSearchParams({
query: router.query,
pathname: router.pathname,
replace: router.replace,
// or
push: router.push,
});

const table = useReactTable({
// Set state and onChanges
...stateAndOnChanges,
data,
columns,
getCoreRowModel: getCoreRowModel(),
getFilteredRowModel: getFilteredRowModel(),
getSortedRowModel: getSortedRowModel(),
// ... other options






Next, I implemented a search feature for this table, as shown below.



CODE
import {
// ...
+ getFilteredRowModel,
} from "@tanstack/react-table";

// ...

export default function UserTable() {
const table = useReactTable({
data,
columns,
getCoreRowModel: getCoreRowModel(),
+ getFilteredRowModel: getFilteredRowModel(),
});

return (
<div>
+ <input
+ placeholder="Search..."
+ value={table.getState().globalFilter}
+ onChange={(e) => table.setGlobalFilter(e.target.value)}
+ />
<table>





The table now supports basic search functionality:







How It Works



To explain how tanstack-table-search-params synchronizes the state of TanStack Table with URL parameters, we will modify the code above to pass only the necessary properties, instead of passing the entire router object and stateAndOnChanges object.



CODE
export default function UserTable() {
const { query, pathname, replace} = useRouter();
const stateAndOnChanges = useTableSearchParams({
query: router.query,
pathname: router.pathname,
replace: router.replace,
});
const table = useReactTable({
state: {
globalFilter: stateAndOnChanges.state.globalFilter,
},
onGlobalFilterChange: stateAndOnChanges.onGlobalFilterChange,
// ...





The reason for passing state.globalFilter and onGlobalFilterChange to useReactTable is to configure the setup for managing TanStack Table state outside of useReactTable.





and returns:




  • state.globalFilter

  • onGlobalFilterChange



and returns it:



Next, onGlobalFilterChange simply returns a function that encodes each part of the TanStack Table state into URL parameters and executes replace.



Both the processes of creating state and onGlobalFilterChange are merely transformations (object → object, function → function), and neither of them holds any internal state. (The only exception is for debouncing, which will be discussed later, where internal state is used for debounce purposes.)





Supported TanStack Table States



Currently, the library supports the following four TanStack Table states, with plans to expand support in the future:




  • globalFilter

  • sorting

  • pagination

  • columnFilters





Supported Routers



As introduced in the How It Works, tanstack-table-search-params simply converts the React state of URL parameters into TanStack Table state. This means it should (probably) work with any router that allows you to retrieve URL parameters as React state.



Examples are available for the following three routers. Feel free to check them out:





  • .



    I’d be thrilled if you gave it a try! (And I’d be even happier if you starred the repository!)







    GitHub logo



    React Hook for syncing TanStack Table state with URL search params.







    TanStack Table Search Params









    React Hook for syncing


    Vollständiger Original-Bericht
    Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
    ↗ Original-Artikel auf dev.to lesen
    Wie bewertest du diesen Beitrag?
    1 Klick Feedback
    Teilen mit Netzwerk & Team:

    Community-Analysen & Experten-Meinungen 0

    Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
    Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
    Community Pulse: Relevanz-Einschätzung
    1 Klick Experten-Votum
    🔴 Akute Relevanz 0%
    🟡 In Evaluierung 0%
    🟢 Keine Auswirkung 0%
    Spannende Innovation 0%
    Verwandte Story-Cluster & Quellen (Vektor-KI)
    Port 8095 Engine
    1 Quelle
    Hackers Just Poisoned the Rust Supply Chain | Threat Wire
    1 Quelle
    Hackers Found a Way Into Humanoid Robots | Threat Wire
    1 Quelle
    Bits und so #1021 (Passwort für Laufwerk)
    Ähnliche Beiträge
    🔍 Verwandte News

    Auch interessante Nachrichten Building a Library to Sync TanStack Table State with URL Parameters

    Thematisch verwandte Begriffe: Building, Library, Sync, TanStack · 6 Treffer

    Laden...

    Videos werden geladen ...

    Laden...

    Beiträge werden geladen ...

    Laden...

    Videos werden geladen ...

    Laden...

    Beiträge werden geladen ...

    Laden...

    Videos werden geladen ...

    Laden...

    Beiträge werden geladen ...

    Laden...

    Videos werden geladen ...

    Laden...

    Beiträge werden geladen ...

    Laden...

    Videos werden geladen ...