You are using inline style style={styles.row}
and using :hover
inside this will not work. You need to define :hover
rule in css explicitly.
For more info, see this post.
:hover is a pseudo-selector and, for CSS, only has meaning within the style sheet. There isn't any inline-style equivalent (as it isn't defining the selection criteria).
Alternatively, you can use onMouseOver
and bind style on this.
<tr key={id} style={styles.row} onClick={click} onMouseOver={hoverrule}>
There's also library Styled-components, and using it allows you to nest css with hover rule.
See this example extracted from here:
import React from 'react';
import styled from 'styled-components';
const Div = styled.div`
margin: 40px;
border: 5px outset pink;
&:hover {
background-color: yellow;
}
`;
const Paragraph = styled.p`
font-size: 15px;
text-align: center;
`;
const OutsetBox = () => (
<Div>
<Paragraph>Get started with styled-components </Paragraph>
</Div>
);
export default OutsetBox;
I am not giving an example with tr because I don't think you really need this library for just using hover style. If you think it would be better to utilize this library, then I hope you can workout with this solution.