Comments (5)
I would expect this generates only the CSS with left: 0;. Is this correct?
Yes, and you can also dynamically change it and it will actually change accordingly! π±
No idea how this works, but it does, after one second left will be set to 50
:
const MyComponent extends React.Component {
state = { left: 0 };
render() {
const FlyingBall = styled.div`
position: absolute;
width: 1rem;
height: 1rem;
left: ${this.state.left}
`;
setTimeout(() => {
this.setState({
left: 50
});
}, 1000);
return <FlyingBall />;
}
from styled-components.
ok, this is cool. Now I'm curious if you used a development or production mode β¦ or to rephrase: If I want to provide cacheable CSS file for production how does it work? Do you identify dynamic styles and set them via the style attribute or inject a style tag?
from styled-components.
inject a style tag?
This, I'm 99% sure. We use aphrodite under the hood, so there's no external CSS file at the moment. Not sure if we want to go down that routeβ¦
from styled-components.
Since #29 (and 0.2.0
), we have simplified this. If you write:
let something;
const X = styled.div`
${ something }
`
Then the value of something
will be locked to its initial value. There's no way around it, unless you call styled.div
inside a render method like @mxstbr does above (you're effectively making a new component each time with whatever the current value of something
is)
If you want something dynamic, though, just interpolate a function!
let something;
const X = styled.div`
${ () => something }
`
Now every time X
is re-rendered that function will be reevaluated and the current value of something
will be injected. Easy!
from styled-components.
Thanks @geelen for the clarification!
from styled-components.
Related Issues (20)
- Export the `toStyleSheet` function HOT 3
- createGlobalStyle not working version >= 5.3.1 HOT 1
- [Docs] Lint for pseudo selectors - Styled Components update from v5 to v6 HOT 1
- Tailwind selectors do not work the expected (from me) way
- React SSR Streaming Bug
- Error while building project after upgrading from 5.3.11 to 6.0.0 HOT 2
- styled-components is ~50% larger than it could be due to IE11 support HOT 1
- Cannot infer the 'as' and 'forwardedAs' props by React.ComponentProps
- Ssr not picking up styled components from an npm package HOT 1
- error TS4023 when compiling a library that uses "styled-components": "^6.1.9" HOT 4
- Required attrs type fixes for 6.1.9 not applied when using prop factory
- Types of `.attrs` are still broken for React Native on 6.1.9 when using `styled()` HOT 2
- Required attrs type fixes for 6.1.9 not applied when using union props HOT 1
- Heap issues in latest 6.1.9 HOT 3
- Regression: `typeof` on a styled component returns incompatible type
- toHaveStyleRule assertion fails after upgrading to 6.1.10 HOT 2
- Use changesets
- Clear cache on view transition
- V6 breaks value-object toString stylesheet interpolation
- Class instance returned from function interpolation causes Component is not a styled component error in v6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from styled-components.