DEV Community

Margaret W.N
Margaret W.N

Posted on

Day 20: Code Refactoring

I refactored the code in consuming API's to two functions as a way to separate concerns. One function gets the habits from the database while the other displays the habits on a webpage.

let getHabits = async function () {
  try {
    const response = await axios({
      url: 'http://localhost:4000/habittracker/habits',
      method: 'get'
  catch (err) {
Enter fullscreen mode Exit fullscreen mode

I'll simply call the displaySavedHabits() function inside the gethabits() and pass in response as a parameter.

let displaySavedHabits = function (response) {
//code to loop through response data and display on a webpage
Enter fullscreen mode Exit fullscreen mode

Meanwhile whats cooking is a function to delete habits from the webpage. I should have the code working in no time.

10 more days down🥳🥳
Day 20

Top comments (1)

nathanbarrett profile image
Nathan Barrett