-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[No QA] No Props/State Destructuring #6234
Conversation
Putting this on HOLD for Expensify/eslint-config-expensify#36 and #6174 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Went about 25% in and just wanted to ask about a few higher level things before continuing.
const { | ||
label, isDisabled, ...pickerProps | ||
} = this.props; | ||
const pickerProps = _.omit(this.props, _.keys(propTypes)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NAB, could maybe opt to be more explicit here vs. depending propTypes
? We are creating a dependency where changing the propTypes
will have a side effect of altering the pickerProps
and not sure if that will be obvious to anyone modifying this (also might make zero difference so 🤷).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like propTypes
is meant to be the main source of truth for the prop types for a component so I personally feel like this pattern is fine. Open to other ideas too, but it feels odd/unnecessary to duplicate all the props in the _.omit
as they're already declared in propTypes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I will just leave you with the thought where someone does not remember to add something to propTypes
and unintentionally passes that prop in pickerProps
. Again, might not be a problem, but the way to prevent it before was clearer i.e. anything not de-structured would be passed and we are changing this to anything not included in propTypes
will be passed - which just feels less obvious.
} = this.props; | ||
|
||
const hasLabel = Boolean(label.length); | ||
const inputProps = _.omit(this.props, _.keys(propTypes)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seeing this again and maybe it's better to pick out which ones we do want to include in inputProps
?
# Conflicts: # src/pages/workspace/WorkspaceInitialPage.js
So the biggest thing it seems we need to agree upon is the pattern to follow for components that use some props, and pass others via a prop spread to a child component. And here are the options as I see them:
So each of these approaches have pros and cons. While So between Thoughts? |
Agree that 2 is the best option, but also was thinking we could use |
# Conflicts: # package.json # src/components/LocalePicker.js # src/pages/NotFound.js # src/pages/ReimbursementAccount/IdentityForm.js
Taking this off hold, should be ready for review now. Thanks! |
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
Unable to load preferences page due to issue in Please see #6267 |
🚀 Deployed to staging by @marcaaron in version: 1.1.14-5 🚀
|
🚀 Deployed to production by @AndrewGable in version: 1.1.15-15 🚀
|
I am tagging this PR to highlight an issue fixed here. All conditions in ternary expressions or left-hand operands on conditional renders, should be boolean. This PR is one of the PRs that uses conditional render with string operands, hence I am tagging it here for the contributors to check. We've also updated the item in the checklist with this PR to avoid this issue in the future. |
Details
Implements a new ESLint rule that bans destructuring of props and/or state.
Fixed Issues
$ #6250
Coming from #5984 (comment)
Tests / QA Steps
Just regression testing. Try to display every view in the app. Keep the JS console open and verify that there are no errors.
Tested On