Redux chrome devtools crashing if bound action creator is not wrapped in another function
See original GitHub issueI came across a strange issue while dispatching actions that have no payload when I have the chrome devtools enabled.
The below code won’t work with devtools-enabled in the store:
Store creation
import { createStore, combineReducers } from 'redux';
import dummyReducer from '../ducks/dummy';
const reducers = combineReducers({
dummy: dummyReducer,
});
const store = createStore(
reducers,
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
);
export default store;
Dummy duck
import { createAction, handleActions } from 'redux-actions';
// Actions
const DUMMY_TOGGLE = 'glen-checkout/DUMMY_TOGGLE';
// Reducer
const initalState = {
isDummy: false,
};
export default handleActions({
[DUMMY_TOGGLE]: state => ({ isDummy: !state.isDummy }),
}, initalState);
// Action Creators
export const toggleDummy = createAction(DUMMY_TOGGLE);
Dummy Connected component
import React, { PropTypes } from 'react';
import { connect } from 'react-redux';
import { toggleDummy } from '../ducks/dummy';
const DummyComp = ({ isDummy, onToggleDummy }) => (
<div style={{ marginTop: 30 }}>
<button style={{ marginRight: 30 }} onClick={onToggleDummy}>Toggle</button>
<span>{isDummy ? 'Oh ma\'h, I am a dummy component! 🐗 ' : 'I am a clever component 🤓 '}</span>
</div>
);
DummyComp.propTypes = {
isDummy: PropTypes.bool.isRequired,
onToggleDummy: PropTypes.func.isRequired,
};
export default connect(
state => ({
isDummy: state.dummy.isDummy,
}),
{
onToggleDummy: toggleDummy,
}
)(DummyComp);
This component won’t be able to dispatch an action if I set onClick={onToggleDummy}
. The console reports the below error when I click on the toggle button:
However if I disable devtools in the store, everything works fine.
That problem can be worked around by wrapping the onClick
handler in a extra function:
onClick={() => onToggleDummy()}
Any ideas why this could be happening?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Redux dev tool crashing when I use this action - Stack Overflow
If the Redux DevTools detect a flow of actions that consume too many resources this will crash because can handle all the "side...
Read more >React, Redux & Material UI Workshop for Beginners - Skillshare
What you'll learn. Create a Todo app from scratch with React; Setup Redux-Saga in the application; Use Material UI components to build the...
Read more >React Js Interview Questions and Answers - TryCatch Classes
Binding in Constructor: In JavaScript classes, the methods are not bound by default. ... Redux wrap it in another function that looks like...
Read more >Learn from 425 web development courses on egghead
Supabase is a collection of open-source tools that wrap around a PostgreSQL database. In this course, we look at building a realtime chat...
Read more >Is redux really a good idea? : r/reactjs - Reddit
Yeah, some might not ask for immutability and some may have a different way to write action object, but other than that everything...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I don’t seem to reproduce the issue with failing to access
toISOString
.However, accessing the synthetic event will still not be possible as described in #275. As we are not allowed to access the object properties without throwing an Error by React (in dev mode only), we cannot detect if this object is an event. So, the only solution to prevent this, would be to check if it’s an instance of
SyntheticEvent
like so:Let me know if this approach works for you.
Ok, just read up on this and the SyntheticEvent solution can no longer be used. Try this instead:
https://github.com/zalmoxisus/redux-devtools-extension/blob/master/docs/Troubleshooting.md#it-fails-to-serialize-data-when-passing-synthetic-events-or-calling-an-action-directly-with-redux-actions