简体   繁体   English

覆盖单独文件React Native中的变量

[英]Overwrite variable in seperate file React Native

To have a constant app styling, I am storing the selected color value in redux store. 为了保持不变的应用样式,我将所选的颜色值存储在redux存储中。 Since not every component has access to this store (would produce too much overhead) I am using a seperate file which exports a variable containing the current selected style. 由于并非每个组件都可以访问该存储(会产生过多的开销),所以我使用了一个单独的文件,该文件导出包含当前所选样式的变量。 Doing this you can easily use this style in every component. 这样做,您可以轻松地在每个组件中使用此样式。

export let primaryColor = '#ff00ff';

Is there a way to overwrite this value without implementing a class structure including getter and setter pattern? 有没有一种方法可以覆盖此值而无需实现包括getter和setter模式的类结构?

you can do like that 你可以那样做

import {primaryColor} from 'path';

let returnMyColor = "#anycolor" ? "#anycolor" : primaryColor;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM