-
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_solituon #1834
base: master
Are you sure you want to change the base?
react_person_solituon #1834
Conversation
src/components/Person/Person.jsx
Outdated
export const Person = ({ | ||
person, | ||
}) => ( | ||
<section className="Person"> |
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.
it's a good practice to use object destructing
export const Person = ({ | |
person, | |
}) => ( | |
<section className="Person"> | |
export const Person = ({ person }) => { | |
const { name, age, ... } = person; | |
return ( | |
<section className="Person"> |
src/components/Person/Person.jsx
Outdated
}) => ( | ||
<section className="Person"> | ||
<h2 className="Person__name"> | ||
{`My name is ${person.name}`} |
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.
no needs to use a template string
{`My name is ${person.name}`} | |
My name is {name} |
src/components/Person/Person.jsx
Outdated
{`My name is ${person.name}`} | ||
</h2> | ||
|
||
{person.age ? <p className="Person__age">{`I am ${person.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.
just use &&
{person.age ? <p className="Person__age">{`I am ${person.age}`}</p> : null } | |
{age && <p className="Person__age">I am {person.age}</p> } |
src/components/Person/Person.jsx
Outdated
{person.isMarried | ||
? `${person.partnerName} is my ${person.sex === 'm' ? 'wife' : 'husband'}` | ||
: '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.
use destructed values
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)
{isMarried | ||
? `${partnerName} is my ${sex === 'm' ? 'wife' : 'husband'}` |
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.
Avoid nesting ternary
Make a variable for this expression
demo