The NewTable API has behaviors like selecting and sorting extracted into hooks.
You can attach these hooks to your table to enhance the experience.
We want to stress that the usage of these hooks is completely optional, you can
create all of these behaviors on your own and by hand.
The objective is to cover the majority of the cases with the hooks and other APIs but still
have the option of overwriting any default, creating flexibility.
How to use the useSort hook
This hook is used for front end sorting. This is not something we usually do at
Carta, but for tables with a small number of rows, this hook can be
handy as it's easy to use.
The hook receives your data Array and an optional config Object with the following
type definition:
type ConfigObject={
/* An initial state for the first render of the hook */
initialState?:{
/* A unique key for the table column */
key: string,
/* Set direction */
direction?:"ascending"|"descending",
},
/* Callback that's called after the sort function */
onSort?:(any)=>void,
/* You can overwrite our internal sorting method by passing a custom one */