React Native External Stylesheet

前端 未结 9 887
你的背包
你的背包 2021-02-03 23:12

Is there a way in React Native that I can put all of my styles in a single file so it can easily be maintained (from my perspective) like in HTML we have a .css fil

9条回答
  •  独厮守ぢ
    2021-02-03 23:45

    According to ECMAScript 6, correct way to export your styles would be like this.

    style.js

    import {StyleSheet} from 'react-native'
    
    export default StyleSheet.create({
    
    container: {
        flex: 1,
        marginTop: 20
    },
    welcome: {
        textAlign: 'center'
    }
    });
    

    Then in your main JS file you can import like this.

    import styles from './style'
    

提交回复
热议问题