Fix hook defaults

This commit is contained in:
tannerlinsley 2019-07-29 11:14:41 -06:00
parent 1caad4cd8c
commit 9b262676be
3 changed files with 17 additions and 10 deletions

View File

@ -1,6 +1,12 @@
module.exports = {
trailingComma: 'es5',
printWidth: 80,
tabWidth: 2,
useTabs: false,
semi: false,
singleQuote: true,
trailingComma: 'es5',
bracketSpacing: true,
jsxBracketSameLine: false,
arrowParens: 'avoid',
endOfLine: 'auto',
}

View File

@ -12,7 +12,6 @@ import {
} from '../utils'
import { useTableState } from './useTableState'
import { useRows } from './useRows'
const propTypes = {
// General
@ -39,7 +38,6 @@ export const useTable = (props, ...plugins) => {
let {
data,
state: userState,
useRows: userUseRows = useRows,
columns: userColumns,
defaultColumn = {},
subRowsKey = 'subRows',
@ -80,9 +78,7 @@ export const useTable = (props, ...plugins) => {
if (debug) console.time('hooks')
// Loop through plugins to build the api out
api = [userUseRows, ...plugins]
.filter(Boolean)
.reduce((prev, next) => next(prev), api)
api = plugins.filter(Boolean).reduce((prev, next) => next(prev), api)
if (debug) console.timeEnd('hooks')
// Compute columns, headerGroups and headers

View File

@ -1,3 +1,4 @@
import React from 'react'
import { useMemo } from 'react'
import PropTypes from 'prop-types'
@ -48,10 +49,14 @@ export const useGroupBy = props => {
// Sort grouped columns to the start of the column list
// before the headers are built
hooks.columnsBeforeHeaderGroups.push(columns => {
return [
...groupBy.map(g => columns.find(col => col.id === g)),
...columns.filter(col => !groupBy.includes(col.id)),
]
// eslint-disable-next-line react-hooks/rules-of-hooks
return React.useMemo(
() => [
...groupBy.map(g => columns.find(col => col.id === g)),
...columns.filter(col => !groupBy.includes(col.id)),
],
[columns]
)
})
columns.forEach(column => {