bdroid
bdroid

Reputation: 614

How i can use variables in stylesheet in React Native?

I want to create general variable color in stylesheet, I created it as shown below, but it does not work.

'use strict';

import {Dimensions} from "react-native";

var React = require('react-native');

var { StyleSheet } = React;

var { PrimaryColor } = "#DDDDDD";

module.exports = StyleSheet.create({

title_post:{
padding: 20,
color: PrimaryColor
},

button_share:{
backgroundColor: PrimaryColor
}

Upvotes: 7

Views: 8097

Answers (1)

madox2
madox2

Reputation: 51911

This is destructuring assignmetn (invalid):

var { PrimaryColor } = "#DDDDDD";

It is used to extract values from an object:

var { a } = { a: 1, b: 2 }
console.log(a) // 1

This is variable declaration and assignment (what you want):

var PrimaryColor = "#DDDDDD";

Upvotes: 4

Related Questions