I'm a newbie in React and I implemented a stateless component, (a "card") which I use very often. But I need it to be available in 3 different widths : Small, medium and large. I was wondering what was the best way to implement it? My first idea was to simply create a component corresponding to each size. But it would be duplicating code :/ Then I thought about giving the size as an argument but it seems... strange?
Asked
Active
Viewed 124 times
0
-
5I think passing size as props would be cleaner implementation in your case – Jayanti Lal May 28 '19 at 12:55
-
It's not strange, it's just how it meant to be. – Mosh Feu May 28 '19 at 12:56
-
@MoshFeu Thanks! So having size="col-lg-4" for example is fine? It seemed weird because I'm using grid :) – The Questionner May 28 '19 at 13:09
-
Do you mean that you're using bootstrap? and you are using the `size` prop by adding a `className` to the parent element inside the component? – Mosh Feu May 28 '19 at 13:27
-
don't use grids, use flex https://css-tricks.com/snippets/css/a-guide-to-flexbox/ – Fakebounce May 28 '19 at 14:20