styled-components
6.6.0 · 12 Oct 2026MIT14.8M / weekRepositoryHomepagenpmAtom feed
4.4.1 is the newest release of 4.x.
In short
10 breaking9 new1 internal
- Breaking
Fix how ampersand is handled in self-referential selector combinations, e.g.
& + &(see #2071) - Breaking
Remove deprecated
consolidateStreamedStylesAPI, - Breaking
Remove deprecated
jsnext:mainentry point from package.json, - Breaking
Remove deprecated
.extendAPI, - Breaking
Migrate to new context API,
- Breaking
Remove TS typings; they are now to be found in DefinitelyTyped,
- Breaking
Add new
data-styled-versionattribute to generated<style>tags to allow multiple versions of styled-components to function on the page at once without clobbering each other, - Breaking
Refactor
keyframeshelper,
Release note
This is a rollup of the highlights of beta 0-11 for convenience. See the migration guide for easy updating steps and the beta announcement blog for our summary of v4's changes, thought process, etc.
New stuff
Add babel macro for full-featured interop with create react app v2+,
Expose
ThemeConsumercomponent, context consumer render prop component from theReact.createContextAPI if people are interested in using it rather than / in addition to thewithThemeHOC,Add
createGlobalStylethat returns a component which, when mounting, will apply global styles. This is a replacement for theinjectGlobalAPI. It can be updated, replaced, removed, etc like any normal component and the global scope will update accordingly,const GlobalStyles = createGlobalStyle` html { color: 'red'; } `; // then put it in your React tree somewhere: // <GlobalStyles />Added a first-class API for rendering polymorphism via "as" prop. In most cases, this new prop will replace your need to use the
.withComponentAPI. It allows you to control what underlying element or component is rendered at runtime, while not messing with the styles,import { Link } from 'react-router' const Component = styled.div` color: red; ` // Examples <Component>Hello world!</Component> <Component as="span">Hello world!</Component> <Component as={Link} to="home">Hello world!</Component>
Breaking changes
- Breaking
Fix how ampersand is handled in self-referential selector combinations, e.g.
& + &(see #2071) - Breaking
Remove deprecated
consolidateStreamedStylesAPI, - Breaking
Remove deprecated
jsnext:mainentry point from package.json, - Breaking
Remove deprecated
.extendAPI, - Breaking
Migrate to new context API,
- Breaking
Remove TS typings; they are now to be found in DefinitelyTyped,
- Breaking
Add new
data-styled-versionattribute to generated<style>tags to allow multiple versions of styled-components to function on the page at once without clobbering each other,It's still highly recommended to use aliasing via your bundler to dedupe libraries like styled-components and react.
- Breaking
Refactor
keyframeshelper,Keyframes is now implemented in a "lazy" manner: its styles will be injected with the render phase of components using them.
keyframesno longer returns an animation name, instead it returns an object which has method.getName()for the purpose of getting the animation name. - Breaking
Migrate to use new
React.forwardRefAPI, by @probablyup; note that this removes theinnerRefAPI since it is no longer needed. - Breaking
Implement
styled()wrapper folding. In a nutshell, when you nest styled wrappers (e.g.styled(styled.div)) the components are now folded such that only one is mounted that contains the merged styles of its ancestors. This is conceptually equivalent to the removed "extend" functionality, but without many of the downsides -- and it's automatic,
Developer experience improvements
Add warning when component is not a styled component and cannot be referred via component selector,
When using CRA v2, import styled components from
styled-components/macroinstead to gain all the benefits of our babel plugin.Add a warning when wrapping a React component with
styled()and theclassNameisn't used (meaning styling isn't applied),Tweak the styled components base component naming to look nicer in DevTools,
Beef up the error message that sometimes occurs when multiple versions of styled components are used together and the StyleSheet instance can't be found,
Misc
Add
enzymeFindtest utility to easily grab instances of a styled-component from enyzme mounted testing scenarios,import { mount } from 'enzyme'; import React from 'react'; import styled from 'styled-components'; import { enzymeFind } from 'styled-components/test-utils'; const Thing = styled.div` color: red; `; const wrapper = mount( <div> <Thing isCool /> </div> ); const thing = enzymeFind(wrapper, Thing); // expect(thing.props()).toHaveProperty('isCool') etc
A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.