Search code examples
react-nativestyled-components

Can not use global styles in styled-components


I am trying to setup global styles in react-native. I have imported

import {injectGlobal} from 'styled-components';

and have

class XoxoContainer extends Component {
  render() {
    return <Xoxo {...this.props} />
  }
}


injectGlobal`
  font-family: '20'
`;

But I keep getting styledComponents.injectGlobals is not a function. in the console.


Solution

  • create a styles.js file like this:

    import React, {Component} from 'react';
    import {
        Platform,
        StyleSheet
    } from 'react-native';
    
    export const styles = StyleSheet.create({
        view_flex_one_white: {
        flex: 1,
        backgroundColor: white
    }});
    

    and use this anywhere in your app with import

        import {styles} from "...link to file/styles";
    
          render(){
             return(
               <View style={styles.view_flex_one_white}>
    
               </View>
        )
    }