-
Notifications
You must be signed in to change notification settings - Fork 4k
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
add getUnhandledProps util #85
Conversation
This is an awesome utility? Could it be extended to work with extra props on classes? I guess it would be hard to tell if the classes are being used or not. Either way 🍂 |
it('leave props not in defaultProps || propTypes in tact', () => { | ||
TestClass.defaultProps = {imHandled: 'thanks'}; | ||
TestClass.propTypes = {alsoHandled: 'got it'}; | ||
const props = {thisShould: 'still be here'}; |
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.
Just a quick question here as to why you chose to make this variable a const
as opposed to a let
? Is it solely because this variable is meant to be read only? Or another, more specific reason?
😃 Just curious
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.
Good question! We've updated the linter. If you make a variable whose value never changes, it will tell you to make it a const instead. The only use case for a let
now is for a variable whose value changes. Example:
let hasCertainChild;
React.Children.forEach(child => {
if (someCondition(child) {
hasSomeChild = true;
}
})
In this case, the var is initialized as undefined
and then set to true
if the condition is met.
Going a bit further, a const wouldn't work here for both of those reasons. It cannot be initialized with an empty value nor can it's value change.
🌊 🐙 Looks super handy |
@eanplatter yes this util works with classes. Classes are just functions with a new name. The important thing is that the util looks for static properties These are equivalent and all produce objects like the above: // ES5
function SomeClass() {}
// ES6
class SomeClass {}
SomeClass.propTypes = {};
SomeClass.defaultProps = {};
// ES7
class SomeClass {
static propTypes = {};
static defaultProps = {};
} Finally, whether or not the class |
…util add getUnhandledProps util
Fixes #69
This util gets all props for a component that are not defined in
propTypes
nor indefaultProps
. These extra props are considered 'unhandled` by the component at hand.The immediate usage of this util will be for spreading props the user passed in that we aren't already explicitly handling.