-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
react person with destructing & variable
- Loading branch information
1 parent
256493c
commit 3bb5268
Showing
3 changed files
with
29 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,28 @@ | ||
export const Person = ({ person }) => ( | ||
<section className="Person"> | ||
<> | ||
<h2 className="Person__name"> | ||
{`My name is ${person.name}`} | ||
</h2> | ||
export const Person = ({ person }) => { | ||
const { name, age, sex, isMarried, partnerName } = person; | ||
const partner = sex === 'm' ? 'wife' : 'husband'; | ||
|
||
{person.age && ( | ||
<p className="Person__age"> | ||
{`I am ${person.age}`} | ||
</p> | ||
)} | ||
return ( | ||
<section className="Person"> | ||
<> | ||
<h2 className="Person__name"> | ||
{`My name is ${name}`} | ||
</h2> | ||
|
||
<p className="Person__partner"> | ||
{person.isMarried === true ? ( | ||
`${person.partnerName} is my ${person.sex === 'm' ? 'wife' : 'husband'}` | ||
) : ( | ||
'I am not married' | ||
{age && ( | ||
<p className="Person__age"> | ||
{`I am ${age}`} | ||
</p> | ||
)} | ||
</p> | ||
</> | ||
</section> | ||
); | ||
|
||
<p className="Person__partner"> | ||
{isMarried ? ( | ||
`${partnerName} is my ${partner}` | ||
) : ( | ||
'I am not married' | ||
)} | ||
</p> | ||
</> | ||
</section> | ||
); | ||
}; |