【发布时间】:2021-12-01 11:42:23
【问题描述】:
我想从我自己的.ts 文件中导出styled-components/macro,但它不起作用。
custom-styled.ts
import styled from 'styled-components/macro'
import * as styledComponents from 'styled-components'
import { ThemeInterface } from './theme'
const {
css,
createGlobalStyle,
keyframes,
withTheme,
ThemeProvider,
} = styledComponents as styledComponents.ThemedStyledComponentsModule<ThemeInterface>
export { css, createGlobalStyle, keyframes, ThemeProvider, withTheme }
export default styled
App.tsx: 当我直接从“styled-components/macro”导入样式导入它时,它会提供预期的调试功能。但是当我从我的自己的文件中尝试时,出现了问题。提前谢谢你。
我试过export { css, createGlobalStyle, keyframes, ThemeProvider, withTheme, styled }。但没有成功。
import React from 'react';
import styled from './custom-styled'
const StyledContainer = styled.div`
background: black;
`
const StyledSpan = styled.span`
color: white;
font-size: 20px;
`
function App() {
return (
<StyledContainer>
<StyledSpan>
Test
</StyledSpan>
</StyledContainer>
);
}
export default App;
【问题讨论】:
-
@ЖнецЪ 使用 react-app-rewrite 的解决方案我认为对于 v4.x+ 来说不是最佳的,正如它在文档中所说的那样。我想我需要在 styled-components repo 中写一个关于这个问题的 GitHub 问题。感谢您的帮助。
标签: javascript reactjs styled-components