You should move the other object to the first attribute of an element. If it is the last, it will replace every attribute.
const Test = ({...other}) => {
const defaultStyle = { '&.test-class-name': {fontSize: 20} }
return <div {...other} className={'test-class-name'} css={{color: 'blue', ...defaultStyle}} >test</div>
}
And if you use CSS in this code: <Test css={{color: 'red'}} />
It will not accept property css. Because library emotion will make change it. you can change it to another name. For example:
<Test style={{color: 'red'}} />
const Test = ({...other}) => {
const defaultStyle = { '&.test-class-name': {fontSize: 20} }
return <div {...other} className={'test-class-name'} css={{color: 'blue', ...defaultStyle, ...(other && other.style)}} >test</div>
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…