I am currently experiencing a structural problem with React and styled-components where I cannot find a seemingly nice solution for every case.
Here's the (quite simple) problem:
<Margin top="10%" left="5%">
<Card>Some text</Card>
</Margin>
The Margin
component extracts the margin settings from the Card
component so that the Card
component can be reused in other scenarios. The Margin
component itself can be reused aswell.
If one wanted to make this responsive though, it would only be possible via different props like topPhone
, topTablet
and so on, which I find very unintuitive and hard to maintain if the responsive boundaries ever change.
So what one could do is duplicate all the content into different other components and display only the one that currently fits (e.g. react-responsive's MediaQuery
component).
But in that case, the page would have a lot of overhead for different device sizes.
What would be the best way to approach this?