Skip to content

Instantly share code, notes, and snippets.

@muZk
Created December 12, 2017 16:42
Show Gist options
  • Save muZk/cdc402c973c2c1e3918f81c392be5c66 to your computer and use it in GitHub Desktop.
Save muZk/cdc402c973c2c1e3918f81c392be5c66 to your computer and use it in GitHub Desktop.
How to use hover with react-jss

How to use hover with react-jss

Let's say we have the following style:

const styles = (theme) => ({
  title: {
    color: theme.color,
  },
})

and we want to change the color when the title is hovered.

In plain CSS we can use psudo classes:

.title:hover{
  color: 'red',
}

While in SASS/LESS:

.title{
  &:hover{
    color: 'red',
  }
}

To accomplish this with react-jss, we can use & operator just like in SASS/LESS:

const styles = (theme) => ({
  title: {
    color: theme.color,
    '&:hover': {
      color: theme.hoverColor,
    }
  },
})

There is a working example: https://codesandbox.io/s/kw3wx5ymkv

@albertBarsegyan
Copy link

thank brother

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment