You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/Troubleshooting.md
+49Lines changed: 49 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -29,3 +29,52 @@ const store = createStore(reducer, preloadedState, compose(
29
29
```
30
30
31
31
Where `batchedSubscribe` is `redux-batched-subscribe` store enhancer.
32
+
33
+
### It fails to serialize data when [passing synthetic events](https://github.com/zalmoxisus/redux-devtools-extension/issues/275) or [calling an action directly with `redux-actions`](https://github.com/zalmoxisus/redux-devtools-extension/issues/287)
34
+
35
+
React synthetic event cannot be reused for performance reason. So, it's not possible to serialize event objects you pass to action payloads.
36
+
37
+
1. The best solution is not to pass the whole event object to reducers, but the data you need:
38
+
```diff
39
+
function click(event) {
40
+
return {
41
+
type: ELEMENT_CLICKED,
42
+
- event: event
43
+
+ value: event.target.value
44
+
};
45
+
}
46
+
```
47
+
48
+
2. Another solution would be to use `event.persist()` (in the example above) as suggested in [React Docs](https://facebook.github.io/react/docs/events.html#event-pooling), but it will consume RAM while not needed.
49
+
50
+
3. If you still need to pass it to an action, you can override this key of the stringified payload in your action creator, by adding a custom `toJSON` function (which will be called by the extension before accessing the object):
51
+
52
+
```diff
53
+
function increment(event) {
54
+
return {
55
+
type: INCREMENT_COUNTER,
56
+
event,
57
+
+ toJSON: function (){
58
+
+ return { ...this, event: '[Event]' };
59
+
+ }
60
+
};
61
+
}
62
+
```
63
+
Note that it shouldn't be arrow function as we want to have access to the function's `this`.
64
+
65
+
As we don't have access to the original object, skipping and recomputing actions during hot reloading will not work in this case. So better to use the required value from the event than the whole event object.
66
+
67
+
4. If you don't want to add `toJSON` to action creators, a solution to prevent this, would be to use `serialize` parameter and to check if it's an instance of `SyntheticEvent` like so:
0 commit comments