Next.js Site with Sanity.io (Headless CMS), styled with SCSS
Design comparison
Solution retrospective
So this project took me about 2.5 weeks to complete, spending several hours most days. For someone who is looking to get into the web development field, is that timeframe reasonable/acceptable?
Another question I had is in regards to the images featured on the site. Basically what I'm doing is loading three versions of each image (mobile, tablet, desktop) into the page and then only showing the correct image, by using "display: none" on the others (I'm doing this using media queries.) Am I correct in assuming that the browser is loading each of the images, which in effect slows the load time? And if so, is there a better way to implement this? Maybe using javascript to find out the screen-width and loading the correct image based on that?
I thought the biggest challenge with this project was figuring out how to set up a headless CMS and load data from there, something I've never tried before. I went with Sanity.io, which offers a lot of helpful documentation and allowed me to actually host the CMS on the site itself (at <live-domain>/admin). I got it to work fine, but I'm curious about other headless CMS examples which might work better?
Finally, I'm using React's context hook to manage the state of my site's shopping cart/checkout process. I was tempted to use Redux but it felt unnecessary. Was this the right decision? There seems to be quite a lot of debate on this topic.
This was a fun project and I learned a lot from it. Any other feedback is welcome and appreciated! Thanks.
Community feedback
- @JunjiequanPosted about 3 years ago
I have used redux, redux-tookilt and redux-thunk for my previous projects.
For me, redux only get complicate when the architecture is not planned thoroughly. In other words, when you are going to use redux it is better to have clear understanding regards to how many state changing activities is need to be included.
The initial step for setting up redux logic is the most difficult & complicated part for me not the code itself make the process complicate. Once the initial setup is done, it makes the whole process much more effective and easy to maintain with useSelector and useDispatch hook, you can always add additional reducers & actions effortlessly.
Lastly, I strongly recommend to tryout redux-thunk. It is a middleware that allows to return a function. Its really usefull when your project is required to interact with server-side, e.g., you could use it to GET data from API and use returned data to dispatch actions, example code below:
export const fetchPosts = () => axios.get(http://localhost:5000/posts); export const fetchAllPosts = async (dispatch: AppDispatch) => { try { const { data } = await fetchPosts(); dispatch({ type: "FETCH_ALL", payload: data }); } catch (err: any) { console.log(err.message); } };
This is just my opinion, I wouldn't consider too much about time spend on a project when I am learning. The more time you spend usually means the more you considerate about the project. For me, it is harder to create good quality project with more time than creepy quality with less time, eye on details require a lot of patient and extra efforts.
Hope this feedback helps.
Marked as helpful0@JamesTheLessFCPosted about 3 years ago@a331998513 Thanks so much for the advice! I have used redux before, including redux-thunk, but it seemed like overkill on this project so that's why I opted for React's Context API instead. I do agree that once redux is set up, it's actually pretty simple. And the Redux dev tools are very helpful for debugging.
0 - @shivjoshi1996Posted about 3 years ago
Hey @JamesTheLessFC, great job on this.
To respond to a couple of your points:
-
I've been a Project Manager for a few years working in Software Eng teams and in my experience, I think for someone who is a Junior F/E, 2 and a half weeks is reasonable for this kind of site considering you were working on it part-time. Obviously, if you had a solid 8-hours a day you might've got this done faster, and as you're still learning, the efficiency of how fast you write your code will only increase going forward. So I think in terms of how fast you're getting things done, you're on the right track.
-
I can't give you a solid answer on the images in terms of best practices (since I'm also learning Sanity & NextJS) but I know Sanity has some special helpers for images (https://www.sanity.io/docs/presenting-images), and there is also a plugin for Sanity + Next specifically. Hopefully that points you in the right direction.
-
From my personal experience Sanity is pretty great (It's the one I've also used the most while developing since it's the most straight forward IMO). For the content, Sanity would work fine. In a real-life situation, you'll probably be asked to hook the shop up to something like Shopify which can handle things like invoices, order tracking, etc. So while you'll still be able to use Sanity for the content (e.g. page content, product descriptions, images) I assume the actual product management will be handled in another system. That's way beyond the scope of this project though so don't worry too much about that! Some other headless CMS' I've used in my real-life role is Prismic (https://prismic.io/) and Contentful (https://www.contentful.com/) but these are mostly for static sites and not for an eCommerce store. I think if you try a couple of them out, the rest should be somewhat similar.
-
From what I've read, the React Context API can be used for most cases rather than Redux which has known to be needlessly complex. For a relatively small project like this, I think Context is perfect.
Great job overall!
Marked as helpful0@JamesTheLessFCPosted about 3 years ago@shivjoshi1996 Thanks for all the feedback and advice! This was very helpful :)
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