Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

styled components :hover with react-native and react-native-web

I'm using styled-components in React-Native App. Let's say I have link component:

import styled from 'styled-components/native';

const Link = styled.Text`
  color: 'red';

  &:hover {
    color: 'blue';
  }
`

After that, I 'compile' my React-Native code with react-native-web.

All is great expect that hover is not working. (Text color remains red on hover.)

My guess is that https://github.com/styled-components/css-to-react-native is removing the hover definition.

Any idea how to fix this?

like image 825
Dávid Ďurika Avatar asked Aug 31 '17 12:08

Dávid Ďurika


People also ask

Does styled-components work with React Native?

React Native is an open-source mobile application framework. With styled components you can build simple, dynamic, and reusable components by writing CSS in your React Native component.

Is styled-components better than CSS?

With styled-components you attach the styles right to the component and don't really name anything. With css-modules, you're applying the styles directly to an HTML element only. With styled-components you can apply the styles to custom components and it will slap the styles on by way of spreading props later.

Is it worth using styled-components?

As seen from the button component example, styled-components allows you to combine CSS and JS in the same file. So, you don't need to create a separate CSS file or keep switching from file to file. This is a huge advantage when creating UI kits because you store all the functionality of the components in one file.


1 Answers

For native mobile development hover doesn't have a definition, that's because there is no cursor on the screen like there is on desktop devices. As React Native for web simulates how RN works, the :hover selector loose its sense

like image 127
Johnny M. Salas Avatar answered Oct 19 '22 12:10

Johnny M. Salas