Describe the bug
Using your sandbox https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/sorting I tried to add a call to toggleSortBy. I get error:
Uncaught TypeError: Cannot read property 'sortDescFirst' of undefined
at eval (index.js:1)
at eval (index.js:1)
at basicStateReducer (react-dom.development.js:16426)
at updateReducer (react-dom.development.js:16482)
at updateState (react-dom.development.js:16621)
at Object.useState (react-dom.development.js:17344)
at Object.useState (react.development.js:1619)
To Reproduce
Go to sandbox. Replace lines 37-50 with:
const {
getTableProps,
getTableBodyProps,
headerGroups,
rows,
prepareRow,
toggleSortBy,
} = useTable(
{
columns,
data,
},
useSortBy
)
toggleSortBy('firstName', false);
Expected behavior
I want the sandbox to sort by firstName.
I solved default sorting as follows:
const {
getTableProps,
getTableBodyProps,
headerGroups,
rows,
prepareRow,
} = useTable(
{
columns,
data,
initialState: {
sortBy: [
{
id: 'firstName',
desc: false,
}
]
}
},
useSortBy
)
@tannerlinsley How would you do this on the column definition?
Most helpful comment
I solved default sorting as follows: