Help me, help you, by helping me, so I don't ask so many questions(yep?)
Here's the site: https://anglian-online.netlify.app/
Here's the code: https://github.com/callum-laing/shopping-site
My question? glad you asked.
See image for a detailed explanation. I created a grid with 3 columns, I was expecting each column to host 1 image/card, however it appears each column is hosting 3 image/cards.
First time attempting this, and I googled 99.95% of it, so I'm sure the code is wrong in probably the app/components/Card.js, but I can't figure out what is wrong.
57 Replies
I'm not a professional by any means
Look where you have div..page_cards__DAsUi.
but I'm 99% sure you're only suppose to have 1 main tag per page. You can achieve what youre looking to do with one grid not having multiples. Also why did you nest grids? (main > div)
You are using the same class with grid-template-columns:repeat(3,1fr) on parent and child.
I'm as confused as you both are
I think I've combined 2 solutions into 1 with my googling
your shop/page.jsx is mapping over all posts to create a card component, but the card component is mapping over all posts as well. so you're doing it double
hmm
I might need to rip it down and try it again then
seems it's quite messy
I second that idea. š
It's my first A) proper react app, B) nextjs app and C) attempting this layout lol
Sure thing, that is how one learns.
uff, I've actually no idea how to do this now haha
What I'm trying to do: take the id from the data.js file, and create a card for every id in the data.js file's array, but have it show as a 3 column grid, so item | item | item
and I'm extremely confused
How does it generate the classes? For starters, just make them different (ir do not generate that div twice).
well this is part of the issue, I really don't know, at all, how to do this, the entire thing is brand new to me lol. I think I map through the array and create a new card for every item in items, but how to put that into the correct positions in grid is what' sconfusing me most
I mean, Matt was right, the main is present in great abundance.
yea I've removed basically all of it, so I'm back to the basics on shop
I bet it is going to be some very stupid omission. It just happens. š
I probably should've tried doing this in vanilla first
I went straight into nextjs
and now my brain is on fire lol
I didn't read most of this but add complexity after you get things working
Like, make the page that you want using regular html css js (inside next) and then start adding the logic and components after
right now I'm just trying to figure out how I create a list of arrays in a data.js file, and then map that list of arrays into their own cards, and I'm struggling even there lol
rofl
now I need the code se
Ok so we need the .card child
err no .cards parent
evanescance - bring me to life, just came on, so we can't mess this up
and it needs to be where?
You need to add .cards based on your css. I'll let you try first
the css is based on the previous answer from googling, so it might need re-doing
I mean its fine
as there's no card.js file anymore
lets get there first
we are in CSS land
this is only from what I see in /stores
ah ok ok
sry shop/***.css and .jsx
only two files we are working with š
I think cards could be shopContainer tbh?
yea if you wanna make that refactor do it to it
cards was just a wrapper to add a grid
then you wont have to add another div
š you got this
yea doesn't make sense to ahve a main, then a div wrapper inside that
I think that actually fixed it, yknow.
so you are combining .shoping container into .cards? then what (missing one step)
boom!
just had to remove cards, move grid-template-columns into .shopContainer, and done
<div className={Styles.cards}>
hint to the one more step
one letter fix š ok two hints
bad teacherwhere are you seeing that?
in the code above, that I got you started with.
I can only see past code remember so I'm working off only that block of code and teh css file actually
I have
yup you got it
with
looks good mate!
š
NOW
make a Card component
š¤£
-.-
no really
and make another ugly module file
and put that .card {} css in it
and learn how to use a component proper
<,<;;
But remember if its not used anywhere else its a hasty abstraction and you are doing cause I told you only for practice.
I mean would i not just cut the code in shop, into the card component, then just import the card component into shop, and use props?
but you do need to understand it and this is good as place as any cause you have "just html" working
Idk thats on you š
I don't wanna think that hard
lmao
hey I got my own shit š¤£ working on my project too atm
damn svelte brain
š
Also I never said couldn't write React..
Just I rather have it easy with :svelte: š
without all the ugly boiler plate bs (nd jsx, and all the wrappers needed just to use it.. "ecosystem of trash wrappers on the ground"
All these concepts are the same, learning components, reactivity(or what passes for it in React), page/component life cycles.
Its all transferable really š
gah I'm spicy today >.>;
yeah I'm still picking up react, but ill jump back to svelte once ive buitl 3-4 things and am comfortable
until then.. embracing the pain
Marks as solved. š
I can actually sleep now, this is great
thanks all š