-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
react_person #2368
base: master
Are you sure you want to change the base?
react_person #2368
Conversation
src/components/Person/Person.jsx
Outdated
{person.age !== undefined ? ( | ||
<p className="Person__age"> | ||
<p>{`I am ${person.age}`}</p> | ||
</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.
{person.age !== undefined ? ( | |
<p className="Person__age"> | |
<p>{`I am ${person.age}`}</p> | |
</p> | |
) : null} | |
{person.age && ( | |
<p className="Person__age"> | |
<p>{`I am ${person.age}`}</p> | |
</p> | |
)} |
src/components/Person/Person.jsx
Outdated
const Married = ({ person }) => { | ||
if (person.isMarried === false) { | ||
return <p>I am not married</p>; | ||
} | ||
|
||
if (person.sex === 'f') { | ||
return <p>{person.partnerName} is my husband</p>; | ||
} | ||
|
||
return <p>{person.partnerName} is my wife</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.
better to write it directly in Person, using ternary operators
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 agree, I already tried to do this but there was one error in the linter when I used two ternary operators (? : ? : )there was something like a wrong rule, although everything worked
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.
That's why I put it in a function so that there is no error in the linter
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.
better to write it directly in Person, using ternary operators
is this error - 12:8 error Do not nest ternary expressions no-nested-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.
you can just move some condition in variable and reuse in ternary operator
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.
you can just move some condition in variable and reuse in ternary operator
thanks for helps))
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.
feel free to ask for some help in the chat
src/components/Person/Person.jsx
Outdated
const Married = ({ person }) => { | ||
if (person.isMarried === false) { | ||
return <p>I am not married</p>; | ||
} | ||
|
||
if (person.sex === 'f') { | ||
return <p>{person.partnerName} is my husband</p>; | ||
} | ||
|
||
return <p>{person.partnerName} is my wife</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.
you can just move some condition in variable and reuse in ternary operator
please double check my code |
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 job. Last thing to fix.
src/components/Person/Person.jsx
Outdated
export const Person = ({ person }) => ( | ||
<section className="Person"> | ||
<h2 className="Person__name">{`My name is ${person.name}`}</h2> | ||
{person.age && ( | ||
<p className="Person__age"> | ||
<p>{`I am ${person.age}`}</p> | ||
</p> | ||
)} | ||
<p className="Person__partner"> | ||
{person.isMarried === false ? ( | ||
<p>I am not married</p> | ||
) : person.sex === 'f' ? ( | ||
<p>{person.partnerName} is my husband</p> | ||
) : ( | ||
<p>{person.partnerName} is my wife</p> | ||
)} | ||
</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.
export const Person = ({ person }) => ( | |
<section className="Person"> | |
<h2 className="Person__name">{`My name is ${person.name}`}</h2> | |
{person.age && ( | |
<p className="Person__age"> | |
<p>{`I am ${person.age}`}</p> | |
</p> | |
)} | |
<p className="Person__partner"> | |
{person.isMarried === false ? ( | |
<p>I am not married</p> | |
) : person.sex === 'f' ? ( | |
<p>{person.partnerName} is my husband</p> | |
) : ( | |
<p>{person.partnerName} is my wife</p> | |
)} | |
</p> | |
</section> | |
export const Person = ({ person }) => { | |
const { name, age, sex, isMarried, partnerName } = person; | |
const partner = sex === 'm' ? 'wife' : 'husband'; | |
const personPartner = isMarried | |
? `${partnerName} is my ${partner}` | |
: `I am not married`; | |
return (<section className="Person"> | |
<h2 className="Person__name">{`My name is ${name}`}</h2> | |
{age && ( | |
<p className="Person__age"> | |
<p>{`I am ${age}`}</p> | |
</p> | |
)} | |
<p className="Person__partner">{personPartner}</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.
thanks for helps))
src/components/Person/Person.jsx
Outdated
{person.isMarried === false ? ( | ||
<p>I am not married</p> | ||
) : ( | ||
<p> | ||
{person.partnerName} is my {partner} | ||
</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.
{person.isMarried === false ? ( | |
<p>I am not married</p> | |
) : ( | |
<p> | |
{person.partnerName} is my {partner} | |
</p> | |
)} | |
{person.isMarried === false ? ( | |
"I am not married" | |
) : ( | |
`${person.partnerName} is my {partner}` | |
)} |
looks like redundant p
tag
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.
awesome
No description provided.