fix: do not error on unkonwn user actions, side-effect-free

This commit is contained in:
tannerlinsley
2019-10-01 20:33:55 -06:00
parent 906988c35a
commit 40477c1c83
4 changed files with 3 additions and 14 deletions
+2 -1
View File
@@ -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
+1
View File
@@ -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'",
-5
View File
@@ -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'`
-8
View File
@@ -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)