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

3.7k Views Asked by At

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)?

Explanation

3

There are 3 best solutions below

3
On BEST ANSWER

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.

0
On

You can add the following rule in you tslint.json:

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

I found a compromise, using a function declaration instead of a variable declaration for my component:

enter image description here