Object.constructor is used as state for reducer named "constructor"
See original GitHub issueWhat is the current behavior?
if combineReducers is passed an object containing constructor
key, initialState is erased and Object.constructor
is used as state instead.
Steps to Reproduce
https://codesandbox.io/s/react-redux-hooks-forked-jf8xe?file=/src/store.js
What is the expected behavior?
making constructor
behave as any other key would be nice, but if there are some technical limitations even warning (both during combineReducers
exectution and docs) would help a lot 👍
Environment Details
“react-redux”: “^7.2.5”, “redux”: “^4.1.1”,
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Understanding React Component Constructor - KnowledgeHut
The React Constructor is a method that's automatically called during the creation of an object from a class. Simply put, the constructor, ...
Read more >Copy prototype functions from object in Redux reducer
So when my app fires this action, it creates a player object for my app to use. The player object has prototype methods...
Read more >Object.prototype.constructor - JavaScript - MDN Web Docs
The constructor data property of an Object instance returns a reference to the constructor function that created the instance object.
Read more >createReducer - Redux Toolkit
createReducer (). Overview. A utility that simplifies creating Redux reducer functions. It uses Immer internally to drastically simplify ...
Read more >4 ways to manage component state - Peanut Butter JavaScript
Method 1: with a class component ; class ClassContactForm extends Component { constructor(props) · super ; '', } } setName = · e)...
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’m legitimately curious: why would you actually have a key named
constructor
in your state in the first place?I’m going to close this because I feel it’s too much of an edge case for us to do anything about. The overall answer here is that using fields named
constructor
orprototype
are potential problems for JS in general, not just Redux.