question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Object.constructor is used as state for reducer named "constructor"

See original GitHub issue

What 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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
markeriksoncommented, Nov 7, 2021

I’m legitimately curious: why would you actually have a key named constructor in your state in the first place?

0reactions
markeriksoncommented, Nov 27, 2021

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 or prototype are potential problems for JS in general, not just Redux.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found