Hey, so in TanStack Table some of the states are n...
# javascript
h
Hey, so in TanStack Table some of the states are not directly primitives or something like
ReadOnlyArray<T>
but they have a little wrapper like
ColumnFiltersTableState
which only has 1 field
var columnFilters: ReadonlyArray<ColumnFilter>
. I want to save the user's settings like sorting, filters, etc. to
localStorage
. The thing is, since
ColumnFiltersTableState
is an external interface I cannot reify it for deserialization. And I cannot just use
ReadonlyArray<ColumnFilter>
directly since it doesn't get explicitly exposed by TanStack, so I get
ReferenceError: ColumnFilter is not defined
when I try it like this. I also can't
JSON.Stringify
since that would create problems in other places, it sometimes adds
_1
to fields.
a
@turansky ^^
h
I now have a
storageKotlin
and
storageJs
function one is reified and uses kotlinx the other isn't and uses
kotlin.js.JSON
. Currently testing if everything works.
t
Both variants can work in fact
h
I would have preferred to just use kotlinx everywhere, but if it's not possible due to external interface restrictions I guess it's okay to have some
JSON.parse
tucked away in abstractions.
t
In case of
stringify
you can use Replacer
h
I think
json.encodeToString
even worked, the main issue was parsing it back from localStorage. Thanks for the answers.