Skip to content

Commit

Permalink
react person with destructing & variable
Browse files Browse the repository at this point in the history
  • Loading branch information
alina-isakova committed Aug 15, 2023
1 parent 256493c commit 3bb5268
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ and use it 3 times inside the `App` instead of static markup.
## Instructions
- Implement a solution following the [React task guideline](https://github.com/mate-academy/react_task-guideline#react-tasks-guideline).
- Open one more terminal and run tests with `npm test` to ensure your solution is correct.
- Replace `<your_account>` with your Github username in the [DEMO LINK](https://<your_account>.github.io/react_person/) and add it to the PR description.
- Replace `<your_account>` with your Github username in the [DEMO LINK](https://alina-isakova.github.io/react_person/) and add it to the PR description.
12 changes: 3 additions & 9 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,10 @@ export const alex = {

export const App = () => (
<div className="App">
<Person
person={misha}
/>
<Person person={misha} />

<Person
person={olya}
/>
<Person person={olya} />

<Person
person={alex}
/>
<Person person={alex} />
</div>
);
45 changes: 25 additions & 20 deletions src/components/Person/Person.jsx
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>
);
};

0 comments on commit 3bb5268

Please sign in to comment.