简体   繁体   中英

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. Typescripts naming convention dictates that we should use lowerCamelCase or UPPER_CASE for the name of const variables.

How can I satisfy both (React and 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

  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:

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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