Design comparison
Solution retrospective
Had some trouble extracting the assets on build and ended up with a hacky function for importing the assets to a specific component. The code can be found in src/components/SummaryCard/SkillCard.jsx. Any feedback on ways you'd tackle this or any eyesores like file/code structure also welcome.
Thanks in advance!
Community feedback
- @markuslewinPosted over 1 year ago
Since the data file expects the memory image to be hosted at
/public/assets/icon-memory.svg
, you can store the image in the project at/public/public/assets/icon-memory.svg
. That way, you can use the URL in the data file as an image source, without having to import the images:<img src={props.datum.icon} alt="" />
If you want to keep importing the images in the JS, I think what you've got is fine! I'd move the images into
/src
, so that it's clear that they're part of Vite's bundling (and not static assets). If you want to get rid of the function, you can put the URLs in an object:const icons = { Memory, Reaction, Verbal, Visual, }; function SkillCard(props) { return <img src={icons[props.datum.category]} alt="" />; }
Marked as helpful1@kaseyveePosted over 1 year ago@markuslewin Super helpful tips that I'll keep in mind for future projects! Many thanks for this!
1
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