I’m fairly new to styled-components and trying to extract / refactor styles to separate files. I have problem with circular dependency - probably because of lacks of experience in styled-components good practices. This is the situation:
// A.js
import { StyledA } from './styles';
export default () => (
<StyledA>
<SomeOtherComponent />
</StyledA>
);
// B.js
import { StyledA1 } from './styles';
export default () => (
<SomeWrapperComponent>
<StyledA1 />
</SomeWrapperComponent>
);
// styles.js
import styled from 'styled-components';
import A from './A.js';
export const StyledA = styled.div`...`;
export const StyledA1 = styled(A)`...`; // causes dependency circle error
What I'm trying to achieve, is to extend A
component styles and keep it's children components (for file B.js
).
export const StyledA1 = styled(StyledA)
doesn't work because I lose componentA
structure.- ...and import
A
instyles.js
causes eslint "dependency-cycle" error because of importsA.js → styles.js → A.js
.
What should I do to keep HTML structure of extended component and resolve dependency cycle issue?
Airbnb
config). Anyway, this is the link. Incomponents/B.js
file you can see (commented out) code before extracting styles to separate file. – chudy91styled
components, see it as a workaround solution instead of trying to fix this specific problem. – Dennis Vash