TSlint和React:如何在导出默认值之前在底部强制执行样式?

时间:2018-12-10 08:01:54

标签: reactjs typescript react-native tslint prettier

我正在用TypeScript构建一个React Native应用程序。我目前正在配置我的TSLint文件。

是否有一种方法可以在同一文档中在文件底部(导出之前)强制实施样式?

例如MyComponent.tsx

import React, { Component } from "react";
import { StyleSheet, Text } from "react-native";
import { SafeAreaView } from "react-navigation";

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center"
  }
});

export class MyComponent extends Component {
  render() {
    return (
      <SafeAreaView style={styles.container}>
        <Text>This screen is my component.</Text>
      </SafeAreaView>
    );
  }
}

export default MyComponent;

应该抛出一个错误,而:

import React, { Component } from 'react';
import { StyleSheet, Text } from 'react-native';
import { SafeAreaView } from 'react-navigation';

export class MyComponent extends Component {
  public render() {
    return (
      <SafeAreaView style={styles.container}>
        <Text>This screen is my component.</Text>
      </SafeAreaView>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    alignItems: 'center',
    flex: 1,
    justifyContent: 'center'
  }
});

export default MyComponent;

应该通过吗?

0 个答案:

没有答案