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
}
Css variables are supported in most browsers so in order to use css variables with React all we need to do is write some css. You can define css variables by using two hyphens, when you define the variable it is important to remember that whatever selector you use will be where the variable scope can exist.
React Native StyleSheet is a way of styling an application using JavaScript code, the main function of react native StyleSheet is concerned with styling and structuring of components in an application, all components of react native make use of a prop known as style, names and properties values work in a similar way as ...
Style attributes React Native mostly use CSS attributes with camelCase instead of kebab-case for styling.
Features. 🎉 You can share your CSS modules between React Native and React Web by using className property in React Native, and by using React Native for Web for the browser. 👌 Supports CSS, PostCSS, Sass, Less and Stylus.
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";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With