FEC-corgis / Jenny-Service-Reviews

Airbnb-styled service-oriented architecture app that generates, persists, and displays product data. Built with MERN, React Styled Components, & React Router DOM.
1 stars 0 forks source link

Refactored App component to react hooks. #4

Closed jhou12 closed 3 years ago

jhou12 commented 3 years ago

@manedurphy @pauly-van @slava000 Could anyone who knows React hooks take a look at my index.jsx refactor? 2 points of interest: 1) Is my syntax is correct and standard? 2) Is useEffect equivalent to componentDidMount?

Thank you!!!

manedurphy commented 3 years ago

Nice refactor @jhou12! The syntax looks good. To address your second question, the useEffect hook achieves the same functionality found in several class-based lifecycle methods (some of which are now deprecated). I personally love this hook because that within that "empty" array as a the second argument, you can insert a variable dependency which will tell the useEffect hook to run every that dependency changes. You may want your logic inside the hook to run multiple times depending on the circumstance which would be the opportunity to take advantage of that functionality.

More info here: https://blog.logrocket.com/lifecycle-methods-with-the-useeffect-hook/