I'm separating my styles in the following way:
styles / |-- base.js |-- base.ios.js |-- base.android.js
Each of them exports a StyleSheet component created as in this example:
import { StyleSheet } from 'react-native'; export default StyleSheet.create({ statusBar: { height: 20 });
How can I merge them so I only have one base style object? I'm looking for something like:
const baseStyles = mergeStyles(baseStyle, platformStyle);
Use the spread syntax to combine multiple inline style objects in React, e.g. style={{...style1, ... style2}} . The spread syntax will unpack the key-value pairs of the objects into a final object and the styles will get applied to the element.
To create global styles with React Native, we can create a module that exports the stylesheet object. import * as React from 'react'; import { View, Text, Button } from 'react-native'; import { Card } from 'react-native-paper'; import styles from './styles'; const App = () => { return ( <View> <Text style={styles.
you are very close:
const baseStyles = [baseStyle, platformStyle];
basically any component can cascade styles like this:
<View style={[styles.style1,styles.style2]}></View>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With