T
TanStack16mo ago
extended-salmon

Should the initial sorting state include the unsorted option

Hi : D I'm trying to control the initial state of a table with query params in a NextJS project. I can control the page and the rows per page no problem with query params passed in as props with default value fallbacks but something like this:
sorting: [
{
id: "title",
desc: searchParams.titleSort === "desc",
},
],
sorting: [
{
id: "title",
desc: searchParams.titleSort === "desc",
},
],
Isn't flexible enough because it constrians the sorting state of the title column to either desc or asc. If the query param for this column isn't defined I'd rather this column remain unsorted. Am I thinking about this problem correctly?
2 Replies
other-emerald
other-emerald16mo ago
just fallback to an empty array if no sorting is set.
extended-salmon
extended-salmonOP16mo ago
ohhhh don't include the object at all in the array, that makes perfect sense lol ty, i'll try that : D

Did you find this page helpful?