Reputation: 1562
I figured I need to use injectGlobal
more than once.
I remember reading in the docs about not using this method more than once in my app.
I have a /globalStyles folder which supposes to collect few different modules into one index.jsx and export 1 injectGlobal
style in the end.
In my case right now I have:
How do I export those modules so I could inject them into 1 injectGlobal
?
I know I can save them in variables as string literal, and just add them as variables into injectGlobal
, but then I won't have the intellisense and coloring styled-components gives.
I'm looking for the best practice if there is one.
Upvotes: 0
Views: 174
Reputation: 4081
You can compose the styles with Styled Component's css
template literal, which should preserve editor intellisense:
reset.style.jsx
import {css} from 'styled-components'
export default css`
// reset styles
`
global.style.jsx
import {css} from 'styled-components'
export default css`
// global styles
`
style.jsx
import {injectGlobal} from 'styled-components'
import resetStyles from './reset.style'
import globalStyles from './global.style'
injectGlobal`
${resetStyles}
${globalStyles}
`
Basically the return value of the css
template literal is also valid in an interpolation. Taking a look at the TypeScript types, the things that can appear in an interpolation are:
css
returns)Upvotes: 1