fitz95 / Math-Magicians

An online calculator
MIT License
1 stars 0 forks source link

Refactoring Code to use React Hooks #4

Open fitz95 opened 1 year ago

fitz95 commented 1 year ago

I used React hooks in the functional components of this react application already so I do not need to refactor my code. In my calculator function, every time a button is pressed onClickHandler function is called and passes a parameter value, which is a string based on the button functionality `` The respective button values are:

-  [0-9]  for numbers
- , +,-,÷,%, x for multiplication  
- AC to clear 
- . for Decimals

the onHandleClick function is attached to a hook that executes the setCalState function https://github.com/fitz95/Math-Magicians/blob/5fcae2260a464dc46ee450066031eb9bb30235f8/src/components/Calculator.js#L11-L13 This function then executes the calculate function provided by Microverse that takes in an Object and a button value parameter

The calculate function returns an object that has three properties which are

Now we display the result on the Ui using a conditional so we display some specific result at a specific time in the calculation flow https://github.com/fitz95/Math-Magicians/blob/5fcae2260a464dc46ee450066031eb9bb30235f8/src/components/Calculator.js#L16-L24

GzimAsani commented 1 year ago

STATUS: APPROVED :100:

There is nothing else to say than it's time to merge... :partying_face:

Cheers and Happy coding! :clap: :computer: :wine_glass: Feel free to leave any questions or comments in the PR thread if something is not 100% clear.

Optional suggestions

Every comment with the [OPTIONAL] prefix is not crucial enough to stop the approval of this PR. However, I strongly recommend you to take them into account as they can make your code better.

You can also consider:

Please be reminded to not open a new pull request after you get a review, only use the same one :thought_balloon:

Please, do not open a new Pull Request for re-reviews. You should use the same Pull Request submitted for the first review, either valid or invalid unless it is requested otherwise.

_As described in the Code reviews limits policy you have a limited number of reviews per project (check the exact number in your Dashboard). If you think that the code review was not fair, you can request a second opinion using this form.