Skip to content
Advertisement

Using the spread operator in styled components

Is it possible to use the spread operator with a styled component in React Native?

I have this component:

JavaScript

But lets say that in my theme, I have an object that has both the fontFamily and the fontSize, and I re use all over the app. I would like to be able to know if I can do something like this, which currently it is not working:

JavaScript

This would be useful too setting up elevation in iOS for example, since I have to setup 4 styles.

Thanks

Advertisement

Answer

You can use the css helper function to generate the specific css and return it as a template literal.

JavaScript

or conditionally as

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement