Skip to content

Commit 2d9e4ec

Browse files
author
Corjen Moll
committed
fix: Fix getting the keys when data is undefined or empty
1 parent 2a2e4f6 commit 2d9e4ec

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ class DataSort extends React.Component {
108108
const { direction } = this.isDirectionControlled() ? this.props : this.state
109109
const { searchQuery } = this.isSearchControlled() ? this.props : this.state
110110
const { pages } = this.state
111-
const keys = this.props.searchInKeys || Object.keys(data[0])
112-
111+
const keys = this.props.searchInKeys || data.length ? Object.keys(data[0]) : []
112+
console.log({ keys })
113113
// Search & sort data
114114
const searched = searchQuery === '' ? data : matchSorter(data, searchQuery, { keys })
115115
const sorted = sortBy === null ? searched : sortData(searched, sortBy, direction)

0 commit comments

Comments
 (0)