OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How dynamically change ThemeProvider values in styled-components?

  • Thread starter Thread starter eugenedrvnk
  • Start date Start date
E

eugenedrvnk

Guest
In my projects I used some global css variables like --space-unit, --header-height and other. And it looked like this :


Code:
  --space-unit: 10px;
  --header-height: 70px;

  @media (max-width: 991px) {
    --space-unit: 7px;
    --header-height: 40px;
  }
  
  @media (max-width: 991px) {
    --space-unit: 5px;
  }

And for different screen resolutions, the variables were appropriate. how do I implement this with styled-components? That is, I create ThemeProvider, enter the initial values of spaceUnit and headerHeight in it, but how do I dynamically change it later?
<p>In my projects I used some global css variables like --space-unit, --header-height and other.
And it looked like this :</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-css lang-css prettyprint-override"><code> --space-unit: 10px;
--header-height: 70px;

@media (max-width: 991px) {
--space-unit: 7px;
--header-height: 40px;
}

@media (max-width: 991px) {
--space-unit: 5px;
}</code></pre>
</div>
</div>
</p>
<p>And for different screen resolutions, the variables were appropriate. how do I implement this with styled-components? That is, I create ThemeProvider, enter the initial values of spaceUnit and headerHeight in it, but how do I dynamically change it later?</p>
Continue reading...
 
Top