mirror of
https://github.com/gosticks/react-table.git
synced 2026-08-16 15:00:27 +00:00
fix: do not error on unkonwn user actions, side-effect-free
This commit is contained in:
+2
-1
@@ -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
|
||||
|
||||
@@ -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,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'`
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user