-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Reader: Update RP on DevDocs #9157
Conversation
Although this is using the same exact data for each RP example. If it's a quick fix and anyone can help me with that, it'd be much appreciated. |
@jancavan I changed it to use a unique source for each post |
3dc0ab3
to
a17ed6d
Compare
<div className="reader-related-card-v2__blocks is-same-site"> | ||
<h1 className="reader-related-card-v2__heading">More in <a className="reader-related-card-v2__link">Cats and Furballs</a></h1> | ||
<ul className="reader-related-card-v2__list"> | ||
{ moreOnSameSite.map( item => |
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.
Should the arrow function body be wrapped with parens since it's multi-line? Like so:
moreOnSameSite.map( item => (
<Component />
)
There's a PR open to change up some of the JS guidelines so I'm not so sure how strict it'll be on wrapping blocks and return values so this is just a suggestion :)
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.
@spentay, thanks for calling this out!
I wasn't sure what our javascript guidelines said on the topic, so I took a peek.
Turns out that for multi-line arrow function we should use braces like so:
moreOnSameSite.map( item => {
return <Component />
} )
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.
Either parens or braces work, just with their own caveats!
Using curlies would require you to explicitly return the component.
However when using parens you don't since the code within them will just be evaluated and returned implicitly to the arrow function.
So these will both essentially do the same thing:
moreOnSameSite.map( item => {
return <Component /> // explict return
} )
moreOnSameSite.map( item => (
<Component /> // implicit return
) )
As a rule of thumb I typically use braces when some sort of extra logic or or variable declarations need to happen within the block before returning the component/value and use parens when the value can just be returned implicitly
Here's a good recent example of the paren usage
This has got me thinking though... the first example labelled as 'bad' uses parens for execution but claims that doing so is 'too magic'... Since it seems to be a fairly common pattern for returning components it might be worth revising or adding another example to the guidelines! I'll get on that and link the PR here :D
<div className="reader-related-card-v2__blocks is-other-site"> | ||
<h1 className="reader-related-card-v2__heading">More in <a className="reader-related-card-v2__link">WordPress.com</a></h1> | ||
<ul className="reader-related-card-v2__list"> | ||
{ moreOnWordPress.map( item => |
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.
Same goes 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.
I approve this message.
This updates the new Related Posts cards on Devdocs.
Before:

After:
