-
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
solution #1618
base: master
Are you sure you want to change the base?
solution #1618
Conversation
00Mass00
commented
Aug 22, 2023
- DEMO LINK
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.
Almost done:smiley:
src/components/Person/Person.jsx
Outdated
{`My name is ${name}`} | ||
</h2> | ||
|
||
{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.
{age && <p className="Person__age">{`I am ${age}`}</p>} | |
{age && ( | |
<p className="Person__age">{`I am ${age}`}</p> | |
)} |
src/components/Person/Person.jsx
Outdated
? `${partnerName} is my ${getPartner()}` | ||
: getPartner() |
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 think will be better to refactor this solution and remove getPartner
function.
Instead of calling getPartner
the second time, we can use 'I am not married' string.
src/components/Person/Person.jsx
Outdated
: HUSBAND; | ||
} | ||
|
||
return 'I am not married'; |
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'm not married' doesn't sound like partner, I'd prefer to create variable and use ternary
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 👍
src/components/Person/Person.jsx
Outdated
const MALE = 'm'; | ||
const WIFE = 'wife'; | ||
const HUSBAND = 'husband'; | ||
const NOT_MARRIED_PERSON = 'I am not married'; |
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.
const NOT_MARRIED_PERSON = 'I am not married'; | |
const NOT_MARRIED_PERSON_MESSAGE = 'I am not married'; |
src/components/Person/Person.jsx
Outdated
export const Person = ({ person }) => { | ||
const { | ||
name, | ||
age, | ||
sex, | ||
isMarried, | ||
partnerName, | ||
} = person; | ||
|
||
const getPartner = () => { | ||
if (isMarried) { | ||
return sex === MALE | ||
? WIFE | ||
: HUSBAND; | ||
} | ||
|
||
return NOT_MARRIED_PERSON; | ||
}; | ||
|
||
return ( | ||
<section className="Person"> | ||
<h2 className="Person__name"> | ||
{`My name is ${name}`} | ||
</h2> | ||
|
||
{age && ( | ||
<p className="Person__age">{`I am ${age}`}</p> | ||
)} | ||
|
||
<p className="Person__partner"> | ||
{partnerName | ||
? `${partnerName} is my ${getPartner()}` | ||
: NOT_MARRIED_PERSON | ||
} | ||
</p> | ||
</section> | ||
); | ||
}; |
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.
Now everything is written correctly, but I offer a more optimized version:
export const Person = ({ person }) => { | |
const { | |
name, | |
age, | |
sex, | |
isMarried, | |
partnerName, | |
} = person; | |
const getPartner = () => { | |
if (isMarried) { | |
return sex === MALE | |
? WIFE | |
: HUSBAND; | |
} | |
return NOT_MARRIED_PERSON; | |
}; | |
return ( | |
<section className="Person"> | |
<h2 className="Person__name"> | |
{`My name is ${name}`} | |
</h2> | |
{age && ( | |
<p className="Person__age">{`I am ${age}`}</p> | |
)} | |
<p className="Person__partner"> | |
{partnerName | |
? `${partnerName} is my ${getPartner()}` | |
: NOT_MARRIED_PERSON | |
} | |
</p> | |
</section> | |
); | |
}; | |
const getPartner = (isMarried) => { | |
if (isMarried) { | |
return sex === MALE | |
? WIFE | |
: HUSBAND; | |
} | |
return NOT_MARRIED_PERSON_MESSAGE; | |
}; | |
export const Person = ({ person }) => { | |
const { | |
name, | |
age, | |
sex, | |
isMarried, | |
partnerName, | |
} = person; | |
const partnerInfo = partnerName | |
? `${partnerName} is my ${getPartner(isMarried)}` | |
: NOT_MARRIED_PERSON_MESSAGE; | |
return ( | |
<section className="Person"> | |
<h2 className="Person__name"> | |
{`My name is ${name}`} | |
</h2> | |
{age && ( | |
<p className="Person__age">{`I am ${age}`}</p> | |
)} | |
<p className="Person__partner"> | |
{ partnerInfo } | |
</p> | |
</section> | |
); | |
}; |
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.
done