【问题标题】:How to share CSS between React and React Native? [duplicate]如何在 React 和 React Native 之间共享 CSS? [复制]
【发布时间】:2021-07-16 00:11:37
【问题描述】:

我们是否应该在 React / Next.js 应用程序中也使用内联 CSS 样式来统一两个项目之间的代码?

像这样?

import {StyleSheet, Dimensions} from 'react-native';

const vw = Dimensions.get('window').width / 100;

export const styles = StyleSheet.create({
  container: {
    paddingTop: 0,
    width: '100%',
    marginTop: 0,
    marginBottom: 0,
    marginLeft: 'auto',
    marginRight: 'auto',
    fontFamily: 'Rubik',
  },
  tableSection: {
    width: '100%',
    marginBottom: 0,
    fontFamily: 'Rubik-Bold',
  },
...

而不是:

.eventOptionTitle {
  word-wrap: break-word;
  text-overflow: ellipsis;
}

.starList {
  list-style-type: none;
  padding-left: 0;
}

【问题讨论】:

    标签: css reactjs react-native next.js shared-libraries


    【解决方案1】:

    我建议查看react-native-web 以进行正确的代码重用,因为它允许使用完全相同的 StyleSheet 对象。由于支持的 CSS 规则集、flex 行为等不同,直接与常规 React Web 应用共享 CSS 肯定很棘手。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-06
      • 1970-01-01
      • 2016-03-22
      • 1970-01-01
      • 1970-01-01
      • 2018-01-15
      • 1970-01-01
      • 2018-07-12
      相关资源
      最近更新 更多