Day 20: Code Refactoring
Margaret W.N
Posted on August 5, 2020
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'
})
displaySavedHabits(response);
}
catch (err) {
console.log(err)
}
}
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
}
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
π πͺ π
π©
Margaret W.N
Posted on August 5, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.