gpt4 book ai didi

javascript - 是否可以将 var styles = StyleSheet.create 从 React.component 分离到不同的脚本中?

转载 作者:数据小太阳 更新时间:2023-10-29 05:41:38 24 4
gpt4 key购买 nike

是否可以在 React Native 中将 var styles = StyleSheet.create 从 React.component 分离到不同的脚本中?

最佳答案

这是可能的。只需使用此模式创建一个 js 文件:

'use strict';

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

var myStyles = React.StyleSheet.create({
style1: { },
style2: { }
)}

module.exports = myStyles;

然后在您的组件 js 中使用 require 来使用该样式表,例如假设你的样式 js 文件被命名为 phongyewtong.js

var s = require('../the/path/to/phongyewtong');

用法:

<View style = {s.style1} />

关于javascript - 是否可以将 var styles = StyleSheet.create 从 React.component 分离到不同的脚本中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32930680/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com