Fix action type detection

This commit is contained in:
tannerlinsley
2019-07-24 07:21:26 -06:00
parent c7d6562d04
commit d1f26fe7bc
2 changed files with 6 additions and 5 deletions
+3 -1
View File
@@ -1,6 +1,7 @@
const actions = {}
const types = {}
export { actions }
export { actions, types }
export const addActions = (...acts) => {
acts.forEach(action => {
@@ -14,5 +15,6 @@ export const addActions = (...acts) => {
// other than importing `{ actions } from 'react-table'`
// and referencing an action via `actions[actionName]`
actions[action] = `React Table Action: ${action}`
types[actions[action]] = true
})
}
+3 -4
View File
@@ -1,6 +1,6 @@
import React from 'react'
//
import { actions } from '../actions'
import { types } from '../actions'
export const defaultState = {}
@@ -32,12 +32,11 @@ export const useTableState = (
const reducedSetState = React.useCallback(
(updater, type) => {
return setState(old => {
if (!actions[type]) {
if (!types[type]) {
console.info({
currentState: old,
stateUpdaterFn: updater,
actionType: type,
supportedActions: actions,
currentState: old,
})
throw new Error('Detected an unknown table action! (Details Above)')
}