Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does styled-components 5.x warn about "Expected style to contain units."

When styling a React Native app with Styled Components 5.x I'm getting the warning...

Expected style "borderWidth: 2" to contain units.

must contain units warning

This didn't happen with previous versions.

What does the warning mean?

like image 426
GollyJer Avatar asked Nov 18 '19 21:11

GollyJer


People also ask

What problem does styled-components solve?

Advantages of using Styled-components Eliminates class name bugs: styled-components provide unique class names for your styles, thus eliminating the problems with class names duplications, misspellings, and overlaps.

Why are emotions over styled-components?

The biggest advantage of Emotion is its easily handled object styles for writing CSS. Take, for example, the case of styled-components, wherein the developer must create unique names for different components, all while avoiding identical naming styles.

Should styled-components be Dev dependency?

Marking styled-components as external in your package dependencies. Moving styled-components to devDependencies will guarantee that it wouldn't be installed along with your library (npm install or yarn add will ignore devDependencies when a library is installed).


1 Answers

After some research and questions on github I tracked this one down...

Styled Components uses the package css-to-react-native for it's React Native conversions.

css-to-react-native recently released version 3 which now requires units to be present for all measurements. Details here.

You should use px for React Native as it is density independent.

like image 70
GollyJer Avatar answered Jan 01 '23 09:01

GollyJer