destructuring-assignment should not trigger when a dynamic property name is accessed
See original GitHub issueExample:
getChildContext() {
return {getProp: (prop) => this.props[prop]};
}
There’s no way to change this to use destructuring, so the rule should not apply unless it’s this.props.foo
or this.props['foo']
.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:8 (7 by maintainers)
Top Results From Across the Web
destructuring-assignment should not trigger when a dynamic ...
I think this is a pretty valid case for children accessing parent props. All reactions.
Read more >Dynamic property destructuring doesn't work for numbers
I'm trying to remove a dynamic property from myObject (in a react project). Here is myObject: myObject = { 'property1': {}, 'property2': {} ......
Read more >Destructuring assignment - JavaScript - MDN Web Docs
Destructuring can be used with property names that are not valid JavaScript identifiers by providing an alternative identifier that is valid.
Read more >Destructuring assignment JavaScript | End Your If
Dynamic Name Property ... Sometimes the property is not known while destructing something. Take a look! Now that we have user objects: Now...
Read more >Destructuring of Props in ReactJS - GeeksforGeeks
A variable name that is not a copy of the property being destructured may be used. This is achieved by reassigning as shown...
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 Free
Top 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
Hi guys, I have a similar question. I’m quite new to React, so please correct me if I err.
I’m using React and Redux, and Redux allows me to expose the action creator functions as props inside my React component (using the
bindActionCreators() function
). I’ve attached my relevant code below, it’s a bit verbose.The problem is that I’m fine with the destructuring pattern, but since
queryVariants
is already imported, I shall not declare another prop using this name. Any suggestions? Thank you![UPDATE] I removed some of the irrelavent code just to show the high-level structure of the component. It may be psuedo-code. The error comes from this line:
onClick={() => { this.props.selectVariant(someData); }}
whereselectVariant()
is exposed as props by redux.But you shouldn’t be dynamically reaching into props; exposing that kind of unfettered prop access to children totally violates the data model of React.