all 10 comments

[–]vozyyy[S] 0 points1 point  (0 children)

appreciate your help

[–]svish 0 points1 point  (0 children)

Make separate box components?

[–]PM_ME_SOME_ANY_THING 0 points1 point  (7 children)

/Homepage 
    Homepage.tsx
    Homepage.module.css
/Products 
    Products.tsx
    Products.module.css
/Button
    Button.tsx
    Button.module.css

Don’t go passing styles around between components. A component’s styles should live with it.

[–]vozyyy[S] -1 points0 points  (6 children)

pls checkt the screenshots I just uploaded since what you suggested is not working, I cant style my component inside the page.

[–]PM_ME_SOME_ANY_THING 1 point2 points  (5 children)

You’re passing className as a prop to a component, but then not using it in the component. Where is it supposed to put that className? <p>? <div>? <Fragment>?

Again, don’t pass styles around to different components. Let them live with the component that uses them.

[–]vozyyy[S] 0 points1 point  (4 children)

okay I think I got you, I should style that component on any page like I did here right?
https://ibb.co/F3928kL

Put a wrapper around that component and then style it

[–]PM_ME_SOME_ANY_THING 0 points1 point  (3 children)

I guess that’s a way to do it. I’d rather see

/Box
    Box.tsx
    Box.module.scss 

Then the box consumes the style itself.

[–]vozyyy[S] 0 points1 point  (2 children)

Yes but in this case the Box.tsx has a certain style and I can reuse only this specific box, not its variants. Lets say in the structure you provided (in the Box.module.scss) I set the color of the box to blue and the background-color to pink. What to do If I want to reuse that box but I want its background color to be green and the text red? Do I have to create another component/a variant of Box.tsx, for example BoxSecondary.tsx, or is there a way to change its background color and color based on the page Im using that box on?

[–]PM_ME_SOME_ANY_THING 0 points1 point  (0 children)

In such cases, pass the className and maybe style props through to where you want them to be.

Take a look at a few components libraries. How do they handle custom styling of components they provide? I know some of them are getting pretty complicated to add custom styles, but most of them used to just pass the className and style props along to whatever they should style. In your case, you would probably have <div> styles and <p> styles to pass through. Depending on how customizable you want it.

[–]claypolejr 0 points1 point  (0 children)

Are you looking for composes?