From bf4b7fb86142cdb8b47a412f2e9aeb9a63735f46 Mon Sep 17 00:00:00 2001 From: Senya Volkov Date: Tue, 11 Feb 2020 17:07:50 +0200 Subject: [PATCH 1/2] solution --- README.md | 2 +- src/App.js | 6 +++++- src/components/Sum.js | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9557b1e8c..76d1f86d3 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Sum component -- Replace `` with your Github username in the [DEMO LINK](https://.github.io/react_sum/) +- Replace `` with your Github username in the [DEMO LINK](https://nizkiyVorobey.github.io/react_sum/) - Follow the [React task guideline](https://github.com/mate-academy/react_task-guideline#react-tasks-guideline) ## Task diff --git a/src/App.js b/src/App.js index 2be7bbc82..88d8981e9 100644 --- a/src/App.js +++ b/src/App.js @@ -1,8 +1,12 @@ import React from 'react'; import './App.css'; +import Sum from './components/Sum'; const App = () => ( -

React sum

+
+

React sum

+ +
); export default App; diff --git a/src/components/Sum.js b/src/components/Sum.js index e69de29bb..c2d7cfe4f 100644 --- a/src/components/Sum.js +++ b/src/components/Sum.js @@ -0,0 +1,22 @@ +import React from 'react'; +import PropTypes from 'prop-types'; + +function Sum(props) { + const { expression } = props; + + return ( +
+ { + expression.map(elem => ( +

{`Sum of ${elem[0]} and ${elem[1]} is ${elem[0] + elem[1]}`}

+ )) + } +
+ ); +} + +Sum.propTypes = { + expression: PropTypes.arrayOf(PropTypes.array).isRequired, +}; + +export default Sum; From ff64f0eed2f4402ba8ebb46958566d43c1824caa Mon Sep 17 00:00:00 2001 From: Senya Volkov Date: Tue, 11 Feb 2020 22:36:41 +0200 Subject: [PATCH 2/2] fixed props --- src/App.js | 4 +++- src/components/Sum.js | 13 ++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/App.js b/src/App.js index 88d8981e9..3bcfc4025 100644 --- a/src/App.js +++ b/src/App.js @@ -5,7 +5,9 @@ import Sum from './components/Sum'; const App = () => (

React sum

- + + +
); diff --git a/src/components/Sum.js b/src/components/Sum.js index c2d7cfe4f..1f3046f33 100644 --- a/src/components/Sum.js +++ b/src/components/Sum.js @@ -2,21 +2,16 @@ import React from 'react'; import PropTypes from 'prop-types'; function Sum(props) { - const { expression } = props; + const { a, b } = props; return ( -
- { - expression.map(elem => ( -

{`Sum of ${elem[0]} and ${elem[1]} is ${elem[0] + elem[1]}`}

- )) - } -
+

{`Sum of ${a} and ${b} is ${a + b}`}

); } Sum.propTypes = { - expression: PropTypes.arrayOf(PropTypes.array).isRequired, + a: PropTypes.number.isRequired, + b: PropTypes.number.isRequired, }; export default Sum;