You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importPropTypesfrom'prop-types'constUserPassword=props=><p>The user password is: {this.props.userpassword}</p>UserPassword.propTypes={userpassword: PropTypes.string.isRequired,}Username.defaultProps={username: 'Jonh',}
to:
importPropTypesfrom'prop-types'constUserName=props=><p>The user name is: {this.props.username}</p>UserName.propTypes={username: PropTypes.string.isRequired,}UserName.defaultProps={username: 'Jonh',}
Reasons
In the original, we see a default for username but we don't see where it's used. In the revision it's clear how the username is used.
In the original, UserPassword is PascalCased, but Username is a single word. In the revision there is only one function, and it's consistently PascalCased.
It's not practical to display a password. It is practical to display a name.
Second Suggestion
Regarding this example:
importPropTypesfrom'prop-types'constUserPassword=(props,context)=><p>User password is {context.password}</p>WowComponent.contextTypes={password: PropTypes.string.isRequired,}
ref:
https://github.com/reactpatterns/reactpatterns-website/blob/main/docs/stateless-function.md
First Suggestion
I recommend a revision of this example
to:
Reasons
Second Suggestion
Regarding this example:
Concerns:
Since there are multiple ways of approaching changes to this example, I'm not providing a suggestion.
Thanks!
The text was updated successfully, but these errors were encountered: