Debug class names do not work when styled function is reexported with macros
See original GitHub issueWhen importing styled
and using it in the same file, debug class names work as expected.
// main.js
import styled from "styled-components/macro";
const Text = styled.div({ color: "red" });
When reexporting the styled function in another file, debug class names disappear
// css.js
import styled from "styled-components/macro";
export { styled }
// main.js
import { styled } from "./css.js";
const Text = styled.div({ color: "red" });
Perhaps this is limitation of the babel macros? If so maybe we should add limitations chapter in the docs (https://www.styled-components.com/docs/tooling#babel-macro).
Versions:
"styled-components": "4.1.3"
"react-scripts": "2.1.3"
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:11 (1 by maintainers)
Top Results From Across the Web
re export styled from styled components macro not working
App.tsx: when I import it directly from import styled from 'styled-components/macro' it gives intended debugging features.
Read more >How To Use Styled-Components In React - Smashing Magazine
Unique class names. Styled components are independent of each other, and you do not have to worry about their names because the library ......
Read more >Build settings reference | Apple Developer Documentation
A detailed list of individual Xcode build settings that control or change the way a target is built.
Read more >Tooling - styled-components
This plugin adds support for server-side rendering, minification of styles, and a nicer debugging experience. Usage. Install the babel-plugin first: npm install ...
Read more >Template Designer Documentation - Jinja
A Jinja template doesn't need to have a specific extension: .html ... If a macro name starts with an underscore, it's not exported...
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 FreeTop 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
Top GitHub Comments
I ran into this issue because I was trying to import
styled
, provide it a theme interface, then reexport it as described here, but using the babel macro instead of the root package.If this is your use case, I think I found a solution. Instead of having the extra
styled-components.ts
file mentioned in the docs, you can redeclare
the"styled-components/macro"
module using your Theme interface, thenimport styled from 'styled-components/macro'
directly. This solves the file-only problem.Here’s what I have in my
global.d.ts
(ITheme
is my theme interface located in a different file):Then, make this change everywhere you imported
styled
previously:I don’t know if the above could be achieved more elegantly, but would love feedback!
I spoke a little too soon – with the above solution, my
props.theme
value in any styled component is anany
rather thanITheme
.