cssreact-native

Margin or Padding Shorthand in React Native


How to define margin/padding shorthand in React Native?

margin: 10px 20px;

Solution

  • When using plain React Native styles you can rewrite your css above to

    {
      marginVertical: 10,
      marginHorizontal: 20
    }
    

    Otherwise the above syntax can be achieved if you're using something like styled-components, which uses css-to-react-native under the hood.