From 40477c1c83dceda16132921e0426d67a96641af4 Mon Sep 17 00:00:00 2001 From: tannerlinsley Date: Tue, 1 Oct 2019 20:33:55 -0600 Subject: [PATCH] fix: do not error on unkonwn user actions, side-effect-free --- docs/api.md | 3 ++- package.json | 1 + src/actions.js | 5 ----- src/hooks/useTableState.js | 8 -------- 4 files changed, 3 insertions(+), 14 deletions(-) diff --git a/docs/api.md b/docs/api.md index a8915a1..158d880 100644 --- a/docs/api.md +++ b/docs/api.md @@ -1008,7 +1008,7 @@ The following options are supported via the main options object passed to `useTa - Optional - Inspired by Kent C. Dodd's [State Reducer Pattern](https://kentcdodds.com/blog/the-state-reducer-pattern-with-react-hooks) - With every `setState` call to a table state (even internally), this reducer is called and is allowed to modify the final state object for updating. - - It is passed the `oldState`, the `newState`, and an action `type`. + - It is passed the `oldState`, the `newState`, and an optional action `type`. - `useState` - Optional - Defaults to `React.useState` @@ -1029,6 +1029,7 @@ The following options are supported via the main options object passed to `useTa - This function signature is **almost** (see next point) identical to the functional API exposed by `React.setState`. It is passed the previous state and is expected to return a new version of the state. - **NOTE: `updater` must be a function. Passing a replacement object is not supported as it is with React.useState** - `type: String` + - Optional - The [action type](TODO) corresponding to what action being taken against the state. ### Example diff --git a/package.json b/package.json index 4eac8a3..f7b8adc 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "main": "dist/index.js", "module": "dist/index.es.js", "jsnext:main": "dist/index.es.js", + "sideEffects": false, "scripts": { "commit": "git add . && git-cz", "test": "is-ci 'test:ci' 'test:dev'", diff --git a/src/actions.js b/src/actions.js index eb7aa74..fa46972 100755 --- a/src/actions.js +++ b/src/actions.js @@ -5,11 +5,6 @@ export { actions, types } export const addActions = (...acts) => { acts.forEach(action => { - if (actions[action]) { - throw new Error( - `An React Table action type called ${action} has already been registered!` - ) - } // Action values are formatted this way to discourage // you (the dev) from interacting with them in any way // other than importing `{ actions } from 'react-table'` diff --git a/src/hooks/useTableState.js b/src/hooks/useTableState.js index fe2f48a..1fe2a4e 100755 --- a/src/hooks/useTableState.js +++ b/src/hooks/useTableState.js @@ -33,14 +33,6 @@ export const useTableState = ( const reducedSetState = React.useCallback( (updater, type) => { - if (!types[type]) { - console.info({ - stateUpdaterFn: updater, - actionType: type, - currentState: overriddenStateRef.current, - }) - throw new Error('Detected an unknown table action! (Details Above)') - } return setState(old => { const newState = updater(old) return reducer(old, newState, type)