-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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 task solution #1610
base: master
Are you sure you want to change the base?
add task solution #1610
Conversation
src/components/Person/Person.jsx
Outdated
{age && ( | ||
<p className="Person__age">{`I am ${age}`}</p> | ||
)} |
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 guess if age is gonna be 0 it's not gonna work correctly, I mean age 0 is not correctly itself, but react will probably just render '0' on the page, so we have to convert it to boolean to make sure it works just fine, we can achieve it by using !! or Boolean
src/components/Person/Person.jsx
Outdated
{isMarried ? ( | ||
<p className="Person__partner"> | ||
{`${partnerName} is my ${sex === SEX_MALE | ||
? 'wife' | ||
: 'husband'}`} | ||
</p> | ||
) : ( | ||
<p className="Person__partner">I am not married</p> | ||
)} |
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.
let's write ternary inside of
tag
- let's create variable to get rid of inner ternary
src/components/Person/Person.jsx
Outdated
{age | ||
? ( | ||
<p className="Person__age">{`I am ${age}`}</p> | ||
) | ||
: null} |
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.
Will be better to use Boolean()
check and use &&
operator instead of ternary one
src/components/Person/Person.jsx
Outdated
: null} | ||
|
||
{isMarried ? ( | ||
<p className="Person__partner"> |
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.
The outer paragraph is the same for both cases
Don't repeat yourself
Let's change only the paragraph content depending on the variable value
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.
Well done 👍
<p className="Person__partner"> | ||
{isMarried | ||
? messageAboutPartner | ||
: messageAboutFreedom} | ||
</p> |
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.
<p className="Person__partner"> | |
{isMarried | |
? messageAboutPartner | |
: messageAboutFreedom} | |
</p> | |
<p className="Person__partner"> | |
{isMarried | |
? messageAboutPartner | |
: messageAboutFreedom | |
} | |
</p> |
DEMO LINK