How can I attach both style1 & style2 to the div below using the Emotion library?
const style1 = css`
display: flex;
`
const style2 = css`
width: 0;
`
const el= () => (
<div css={style1}>
)
In Emotion you can do what's called composition:
const style1 = css`
display: flex;
`
const style2 = css`
width: 0;
`
const el= () => (
<div
css={css`
${style1};
${style2};
`}
>
)
The above solution can be simplified as follows:
const el= () => (
<div css={[style1, style2]}>
)
This type of composition for CSS objects is also in the documentation (but not easy to find): https://emotion.sh/docs/best-practices#method-1-export-css-objects
const style1 = css({
display: flex;
})
const style2 = css({
width: 0;
})
const combinedStyles = css([style1, style2])
const el= () => (
<div css={combinedStyles}>
)