Interactive e-commerce product page using React, Redux & Sass
Design comparison
Solution retrospective
Hello, It took me about 25 hours to build it. Looking forward to any feedbacks, especially on the way I structure my code, and the amount of time it took me to solve the challenge.
#nothing_is_hard_coded_here
Thank you! a special thanks to #frontendmentor.io team.
Community feedback
- @fazzaamiarsoPosted over 2 years ago
Hello there! Great solution overall!
I found some critical problems in your code.
- You don't wrap the
addEventListener
inuseEffect
. Why it's problematic? the consequence of not attaching event listeners inuseEffect
is that you can't remove the listener after re-rendering. So, you are effectively attaching new listeners every render, which can slow down performance. Here is my improvement
useEffect(()=>{ // must create a separate function so it can be removed const resizeFunction = () => { if (window.outerWidth <= 768 && isLightBoxOpen) { dispatch(toggleLightbox(-1, -1)) } } window.addEventListener('resize', resizeFunction) return () => window.removeEventListener('resize', resizeFunction) //cleanup function }, [dispatch, isLightBoxOpen])
- Mirrored props in a state. Here is the problematic state.
const [numberOfProduct, setNumberOfProduct] = useState(props.product.numberInCart)
Why it's a problem? because React won't re-initialize the state when
props.product.numberInCart
changes in a re-render. So, you are at risk of having a stale state. But, if you just want it to be an initial state, that is not a problem. You can read more on the official docs about this specific problem.Hope it's helpful! Goodluck!
Marked as helpful3@hikmatullah-mohammadiPosted over 2 years ago@fazzaamiarso Thank you for your time and tremendous feedbacks. I fixed the first one, and the second one is OK since I use
setNumberOfProduct
whenever it needs updating.Happy coding...
0 - You don't wrap the
- @kofinarteyPosted over 2 years ago
Awesome job mate. Here a few changes I figured you could implement. *You seem to have forgotten to set the font to what was specified in the design guide: a simple css import could fix that.
*On mobile, the nav items do not get hidden and neither do you render the hamburger menu.
*And it also seems the carousel is stuck to just one form as opposed to the different versions for mobile and desktop.
Great work all the same. Keep pushing💪
Marked as helpful1@hikmatullah-mohammadiPosted over 2 years ago@kofinartey Thank you for your time and feedbacks.
- I set the font.
- The nav is behaving properly, may be there is any issues with your browser.
- I tried a couple of ways to deal with the carousels properly, but I could not find any good solution for so.
Happy coding...
0
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