Design comparison
Solution retrospective
Due to data.json format, i mapped three times the data to store just 3 parts of code that would be sended to the three components that needed that specific part of data, but i don't think is a good idead to map that amount of time, since de data could be bigger and can be inneficient. So i'm wondering if there is a simplest way to fetch the data and by mapping just one time, divide the data in three and then send what each component requires.
Any help will be apreciated, thanks!
Community feedback
- @elaineleungPosted over 2 years ago
Hi Juan, about using
map()
three times:You can try using
forEach()
instead. When you usemap()
, you will always get an array back with whatever modifications you done to it, whereasforEach()
simply loops through each item of the array without returning that item in the array, unless you tell it to do so. Since you want to actually return an object and not the array in the data, you can try something like this:Start with creating an object with the three timeframes, with each key getting an empty array:
const dataObj = { daily: [], weekly: [], monthly: [] }
And then use
forEach()
like this within your.then()
:data.forEach( item => { const { title, timeframes } = item const { daily, weekly, monthly } = timeframes // I deconstructed the objects just to simplify things dataObj.daily.push({ title: title, timeframes: daily }) dataObj.weekly.push({ title: title, timeframes: weekly }) dataObj.monthly.push({ title: title, timeframes: monthly }) }) setData(dataObj)
Hope this helps, and great job with writing your dashboard in React!
Marked as helpful1 - @mubizzyPosted over 2 years ago
Excellent job on this challenge! your report has a few issues though:
- wrap everything in your body in
<main>
or use semantics
2. it is a best practice to use both HTML 5 and ARIA landmarks to ensure all content is contained within a navigational region.
Hope it helps:)...don't forget to mark it as helpful 👍
You can get more details here...click here
0 - wrap everything in your body in
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord