From d1f26fe7bc59d79e598b429611a1980ee2893b76 Mon Sep 17 00:00:00 2001 From: tannerlinsley Date: Wed, 24 Jul 2019 07:21:26 -0600 Subject: [PATCH] Fix action type detection --- src/actions.js | 4 +++- src/hooks/useTableState.js | 7 +++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/actions.js b/src/actions.js index 2168420..eb7aa74 100755 --- a/src/actions.js +++ b/src/actions.js @@ -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 }) } diff --git a/src/hooks/useTableState.js b/src/hooks/useTableState.js index 4c0d3e1..52ac612 100755 --- a/src/hooks/useTableState.js +++ b/src/hooks/useTableState.js @@ -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)') }