hifromkevin / Magic-Mirror-on-the-Wall

The UI for my Raspberry Pi magic mirror build.
2 stars 0 forks source link

Refactor #4

Open mattlaguardia opened 5 years ago

mattlaguardia commented 5 years ago

RE: From you asking me to do a code review FYI - I'm not sure how some of these APIs work so forgive me if I don't realize something I did this at a quick glance.

For file: client/src/components/App.jsx

Consider updating to the functional API (react hooks) instead of the component lifecycle (since react is moving away from componentDidMout etc).

For API calls if you'd like to clean up some of the code I'd refactor to async / await so it would be more legible. Idk if I wrote this right but I think it gets the idea across.

const getWeather = async () => {
  try {
    let getInitData = await fetch('api-endpoint)
    let res = await getInitData.json()
    let getWeatherData = await fetch('api-endoint/${lat}/${long}'
    let weather = await getWeatherData.json()
  } catch (err) {
    throw error
  }
}

For file: client/src/lib/index.js

For your functions, I would consider using const instead of let because it will throw an error if this application got large and you overwrote/used the same name. I think it's a better practice to use const on functions.