How to change the style of components dynamically?
See original GitHub issuehttps://www.webpackbin.com/bins/-Kon08wq7y0PT-JC4ufF
This is my current code. Since the stylesheet is static there is no way I can pass props to objects inside it. So my current approach is to use some defined classes like.
const styles = {
bar: {
background: '#f00',
},
greenBar: {
background: 'green',
},
};
and do this
<LinearProgress classes={{ bar: props.classes[props.color] }} />
call using
<Progress color="greenBar" />
It’s not perfect, it’s not even good I think but I would like to know what are the possibilities?
Issue Analytics
- State:
- Created 6 years ago
- Comments:13 (6 by maintainers)
Top Results From Across the Web
How to change style of styled-component dynamically?
Another simple solution can be with passing the id attribute to your button and querying it on button click. const ButtonsRow = styled.div` ......
Read more >Make Your CSS Dynamic With Styled Components
import React from "react"; import styled from "styled-components"; const Wrapper = styled.div` font-family: sans-serif; `; const Button ...
Read more >6 ways to dynamically style Angular components - Medium
The simplest way to update the style of your component is by using ngClass . This directive can dynamically add or change the...
Read more >How to change the style of components dynamically? #7408
Use CSS variables if you target browsers support it; Use another styling solution; Wait for the upgrade of JSS that support rule' properties...
Read more >React: How To Change Background Color Dynamically On Click
react #reactjs #webdev #coding #programming how to change background color in react dynamically ? This tutorial will show you How To Change ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@ConneXNL I know it’s a closed issue, but for anyone stumbling across this, to use react-jss with material-ui, all you have to do is replace material-ui’s
withStyles()
method with react-jssinjectSheet()
, and the Themeprovider component in place of MuiThemeProvider.@oliviertassinari, the point of @dsslimshaddy is a good way to solve that problem but another approach is implement a property that modifies the property of a inner component, in this case, you could implement an property called barProps and using this you could use the property style to modify the style of the inner element: