question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't use Pascal case when declaring a stateless functional component (SFC)

See original GitHub issue

I’m currently having issues declaring SFCs when using the following tslint configuration:

{
  "extends": ["tslint-config-airbnb", "tslint-react", "tslint-config-prettier"]
}

and here is a sample component

import * as React from 'react';

const DummyComponent = () => <div>Hello World!</div>;

export default DummyComponent;

which results in the error

[tslint] variable name must be in lowerCamelCase or UPPER_CASE (variable-name)
const DummyComponent: () => JSX.Element

I know that it is the tslint-config-airbnb causing the issue, but I would have thought that tslint-react would have a rule for Pascal cased SFCs.

I think that this rule is missing. I’d be happy to throw up a PR if that’s the case. I just need to read up a bit on creating rules.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:67
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

62reactions
mellis481commented, Nov 14, 2018

You can do this:

const dummyComponent = () => <div>Hello World!</div>;

export { dummyComponent as DummyComponent };
20reactions
nickytonlinecommented, Nov 1, 2017

For now, I’m doing this, but it’s just a hack, as it allows people to write all vars as Pascal case.

{
  "extends": ["tslint-config-airbnb", "tslint-react", "tslint-config-prettier"],
  "rules": {
    // This rule is here for now because of https://github.com/palantir/tslint-react/issues/120
    "variable-name": [true, "ban-keywords", "check-format", "allow-pascal-case"]
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

TSLint and React stateless component naming (PascalCase ...
I found a compromise, using a function declaration instead of a variable declaration for my component: enter image description here.
Read more >
dsny_dashboard - npm
SFC <P>. Type representing stateless functional component ... Reference Naming: Use PascalCase for React components and camelCase for their ...
Read more >
React Stateless Functional Component with TypeScript
Use React Stateless Functional Component when you don't need to manage states in a component. TypeScript supports SFC type that is the alias ......
Read more >
Building React Stateless Functional Components ... - Pluralsight
Stateless functional components are an awesome way to decouple complex architecture from the design of a component's output.
Read more >
Stateless component in React and "Props is defined but never ...
Coding example for the question Stateless component in React and "Props is defined but never used" ESLint error-Reactjs.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found