Im started learn react, but can’t understand, why my style doesn’t work in @hover?
Button – is a custom library button. By default I can change its color in "style" line, but I can’t change it on hover effect.
const linkStyle = {
background: 'red',
'&: hover': {background: 'blue'}
}
export default function App() {
return (
<Theme className="App">
‹Button
label="My Button"
iconLeft={IconAlert}
size="m"
style={linkStyle}
</Theme>
Where am I wrong?
I tried many many many times
2
Answers
hover can’t be applied at inline-css, you can use the sx prop to provide the CSS –
By React best practices, it’s better to split your component into 2 different files, ie; component file and styling file. Finally import the style into the component file to enable the CSS styles declared. Example based your code above as below:
CSS file
React Component File
This should work if your component file and styles file are in the same directory or folder. Hope this helps