React Native External Stylesheet

前端 未结 9 901
你的背包
你的背包 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:28

    Yes you can

    • First create a file name style.js and create what ever style you want like the following example:

    Style.js

    module.exports = {
    
        "centerRowAligment":{
            flex: 1,
            backgroundColor:"#a22a5f",
            flexDirection: 'row',
            alignItems:"center"
        },
        "centerColumnAligment":{
            flex: 1,
            justifyContent: 'center',
            flexDirection: 'column',
            alignItems: 'center'
        }
    
    }
    

    Then in your react file just import it

    import styles from './style'
    

    And then use it in the render components

       
    

    This should works fine !

提交回复
热议问题