Passing props into external stylesheet in React Native?

后端 未结 4 1386
臣服心动
臣服心动 2020-12-16 14:08

I\'m new to React and React Native. At the moment for each component I\'m breaking the code into 2 separate files:

  1. index.js for all the React cod
4条回答
  •  误落风尘
    2020-12-16 14:34

    I rather to have my styles in a separate file styles.js. Inside styles.js:

    export const styles = (props) => StyleSheet.create({
            icon : {
            color: props.iconColor,
            fontSize: props.iconSize
          }
        }
    

    Inside your main class you can pass the value

    return (
        
      );
    

    Alternatively you can those value directly so it would be

    export const styles = (iconColor,iconSize) => StyleSheet.create({
        icon : {
        color: iconColor,
        fontSize: iconSize
      }
    }
    

    and inside your main class

    return (
        
     );
    

提交回复
热议问题