【问题标题】:Handle no-unused-styles for dynamic stylesheet处理动态样式表的非未使用样式
【发布时间】:2022-11-05 15:26:44
【问题描述】:

在 react-native 中,使用如下动态样式:

const myComponent = () => {

    const styles = createStyles(theme)

    return (
        <View style={styles.container}>
        </View>
    )
}

const createStyles = theme => StyleSheet.create({
    container: {
        backgroundColor: theme.background,
    },
})

我如何避免从 react-native/no-unused-styles 收到 eslint 警告?

【问题讨论】:

  • 有什么解决办法吗?...

标签: react-native eslint


【解决方案1】:

不是最好的解决方案,而是我想到的唯一一个,因为这里的 eslint 是错误的......

const styles = ({ color }: ListDecorationProps) =>
  StyleSheet.create({
    // eslint-disable-next-line react-native/no-unused-styles
    bullet: {
      borderRadius: 999,
      zIndex: 5,
      width: 20,
      height: 20,
      backgroundColor: color,
    },
  });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-04
    • 2020-12-01
    • 2021-07-27
    • 1970-01-01
    • 1970-01-01
    • 2020-08-19
    • 2015-04-07
    • 1970-01-01
    相关资源
    最近更新 更多