简体   繁体   English

TSLint和React无状态组件命名(PascalCase与camelCase)

[英]TSLint and React stateless component naming (PascalCase vs. camelCase)

Stateless React components should be named in PascalCase , so React can distinguish between native elements and components. 无状态React组件应该在PascalCase中命名,因此React可以区分本机元素和组件。 Typescripts naming convention dictates that we should use lowerCamelCase or UPPER_CASE for the name of const variables. Typescripts命名约定规定我们应该使用lowerCamelCase或UPPER_CASE作为const变量的名称。

How can I satisfy both (React and tslint)? 我怎样才能满足(React和tslint)?

说明

I think you have two options here: 我想你有两个选择:

  1. Use where appopriate comment like this 使用这样适当的评论

    /* tslint:disable-next-line:variable-name */

    to disable tslint warning at that particular line 禁用该特定行的tslint警告

  2. Use class components instead of functional ones. 使用类组件而不是功能组件。

您可以在tslint.json中添加以下规则:

"variable-name": [true, "ban-keywords", "check-format", "allow-pascal-case"]

I found a compromise, using a function declaration instead of a variable declaration for my component: 我发现了一个妥协,使用函数声明而不是我的组件的变量声明:

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM