Skip to content
Permalink
Browse files

Fix hook defaults

  • Loading branch information...
tannerlinsley committed Jul 29, 2019
1 parent 1caad4c commit 9b262676bed18eb8da8734cf509ba7da6219bcf1
Showing with 17 additions and 10 deletions.
  1. +7 −1 prettier.config.js
  2. +1 −5 src/hooks/useTable.js
  3. +9 −4 src/plugin-hooks/useGroupBy.js
@@ -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',
}
@@ -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
@@ -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 => {

0 comments on commit 9b26267

Please sign in to comment.
You can’t perform that action at this time.