Styled component, eslint with react native gets "no-unused-vars"

Lia*_*ang 5 eslint react-native styled-components

'Text' is defined but never used  no-unused-vars
Run Code Online (Sandbox Code Playgroud)

Here is the code section gets error

import {
  Text,
  StyleSheet,
} from 'react-native';
import color from './color';

export const Sub = styled.Text`
  color: ${color.secondary};
  font-size: 16;
  text-align: center;
  margin: 8px;
Run Code Online (Sandbox Code Playgroud)

as we can see the Text has been consumed by Sub, since we don't want remove the no-unused-vars rule, we may need a plugin or setting to walk-around this


Thanks @Dan, you saved me from my tunnel vision

小智 3

假设这Text是一个组件,文档说声明它的正确方法是:

export const Sub = styled(Text)`
  color: ${color.secondary};
  font-size: 16;
  text-align: center;
  margin: 8px;
`
Run Code Online (Sandbox Code Playgroud)

它还可以解决 eslint 问题。