Skip to content

Commit fb22912

Browse files
cloeperphryneas
andauthored
Add section to usage guide on working with non-serializable data (#623)
* Adds section to usage guide on how to allow non-serializable values, updates error message in serializableStateInvariantMiddleware to link to new section in usage guide * fix syntax error * fixes * update tests * remove space at line ending Co-authored-by: Lenz Weber <mail@lenzw.de>
1 parent 7a0c98a commit fb22912

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

docs/usage/usage-guide.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,3 +1021,18 @@ export const usersAdapter = createEntityAdapter({
10211021
sortComparer: (a, b) => a.first_name.localeCompare(b.first_name)
10221022
})
10231023
```
1024+
1025+
## Working with Non-serializable Data
1026+
1027+
Occasionally, you may have actions that need to accept non-serializable data. This should be done very rarely and only if necessary. These non-serializable payloads shouldn't ever make it into your application state through a reducer. However, if you're using libraries such as redux saga or you're using middleware that could reasonably use non-serializable data you'll want to do the following:
1028+
1029+
```js
1030+
configureStore({
1031+
//...
1032+
middleware: getDefaultMiddleware({
1033+
serializableCheck: {
1034+
ignoredActions: ['your/action']
1035+
}
1036+
})
1037+
})
1038+
```

src/serializableStateInvariantMiddleware.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ describe('serializableStateInvariantMiddleware', () => {
111111
Take a look at the logic that dispatched this action: Object {
112112
\\"type\\": Symbol(SOME_CONSTANT),
113113
}
114-
(See https://redux.js.org/faq/actions#why-should-type-be-a-string-or-at-least-serializable-why-should-my-action-types-be-constants)"
114+
(See https://redux.js.org/faq/actions#why-should-type-be-a-string-or-at-least-serializable-why-should-my-action-types-be-constants)
115+
(To allow non-serializable values see: https://redux-toolkit.js.org/usage/usage-guide#working-with-non-serializable-data)"
115116
`)
116117
})
117118

@@ -363,7 +364,8 @@ describe('serializableStateInvariantMiddleware', () => {
363364
},
364365
\\"type\\": \\"test\\",
365366
}
366-
(See https://redux.js.org/faq/actions#why-should-type-be-a-string-or-at-least-serializable-why-should-my-action-types-be-constants)"
367+
(See https://redux.js.org/faq/actions#why-should-type-be-a-string-or-at-least-serializable-why-should-my-action-types-be-constants)
368+
(To allow non-serializable values see: https://redux-toolkit.js.org/usage/usage-guide#working-with-non-serializable-data)"
367369
`)
368370
})
369371

src/serializableStateInvariantMiddleware.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ export function createSerializableStateInvariantMiddleware(
176176
value,
177177
'\nTake a look at the logic that dispatched this action: ',
178178
action,
179-
'\n(See https://redux.js.org/faq/actions#why-should-type-be-a-string-or-at-least-serializable-why-should-my-action-types-be-constants)'
179+
'\n(See https://redux.js.org/faq/actions#why-should-type-be-a-string-or-at-least-serializable-why-should-my-action-types-be-constants)',
180+
'\n(To allow non-serializable values see: https://redux-toolkit.js.org/usage/usage-guide#working-with-non-serializable-data)'
180181
)
181182
}
182183
})

0 commit comments

Comments
 (0)