Skip to content

Commit

Permalink
fix(useHandleSortState): fix import issue
Browse files Browse the repository at this point in the history
This PR fixes an reported issue with the current documented import.
  • Loading branch information
tujoworker committed Dec 16, 2022
1 parent c16519d commit 03a2791
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ By default, it will cycle trough three stages `['asc', 'desc', 'off']`.
</summary>

```jsx
import { useHandleSortState } from '@dnb/eufemia/components/table'
import useHandleSortState from '@dnb/eufemia/components/table/useHandleSortState'

// You can also provide a default that will be used as the fallback e.g.
const defaultOptions = { direction: 'asc', modes: ['asc', 'desc', 'off'] }
Expand All @@ -99,6 +99,24 @@ export const YourComponent = () => {
console.log(sortState.column1.direction) // returns either "asc", "desc" or "off"
console.log(activeSortName) // returns the current active one: "column1" (returns null when nothing is active)

// Handle your logic
useEffect(() => {
switch (sortState.column1.direction) {
default:
case 'asc':
setYourLocalState(mockData.sort(compareFunctionAsc))
break

case 'desc':
setYourLocalState(mockData.sort(compareFunctionsDesc))
break

case 'off':
setYourLocalState(mockData)
break
}
}, [sortState.column1.direction])

return (
<Table>
<thead>
Expand Down
1 change: 0 additions & 1 deletion packages/dnb-eufemia/src/components/table/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
*/

import Table from './Table'
export { useHandleSortState } from './useHandleSortState'
export default Table
export * from './Table'
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import TableContainer from '../TableContainer'
import { H2, P, Anchor, Dl, Lead } from '../../../elements'
import { Button, ToggleButton, NumberFormat, Avatar } from '../../'
import shopping_cart from '../../../icons/shopping_cart'
import { useHandleSortState } from '../'
import useHandleSortState from '../useHandleSortState'

export default {
title: 'Eufemia/Components/Table',
Expand Down

0 comments on commit 03a2791

Please sign in to comment.