Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docs] display-name: improve examples #3189

Merged
merged 1 commit into from Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -18,7 +18,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
* [Docs] HTTP => HTTPS ([#3133][] @Schweinepriester)
* [readme] Some grammar fixes ([#3186][] @JJ)
* [Docs] [`jsx-no-target-blank`]: Improve readme ([#3169][] @apepper)
* [Docs] [`display-name`]: improve examples ([#3189][] @golopot)

[#3189]: https://github.com/yannickcr/eslint-plugin-react/pull/3189
[#3186]: https://github.com/yannickcr/eslint-plugin-react/pull/3186
[#3174]: https://github.com/yannickcr/eslint-plugin-react/pull/3174
[#3169]: https://github.com/yannickcr/eslint-plugin-react/pull/3169
Expand Down
16 changes: 14 additions & 2 deletions docs/rules/display-name.md
Expand Up @@ -12,6 +12,14 @@ var Hello = createReactClass({
return <div>Hello {this.props.name}</div>;
}
});

const Hello = React.memo(({ a }) => {
return <>{a}</>
})

export default ({ a }) => {
return <>{a}</>
}
```

Examples of **correct** code for this rule:
Expand All @@ -23,6 +31,10 @@ var Hello = createReactClass({
return <div>Hello {this.props.name}</div>;
}
});

const Hello = React.memo(function Hello({ a }) {
return <>{a}</>
})
```

## Rule Options
Expand All @@ -37,7 +49,7 @@ var Hello = createReactClass({

When `true` the rule will ignore the name set by the transpiler and require a `displayName` property in this case.

Examples of **correct** code for this rule:
Examples of **correct** code for `{ ignoreTranspilerName: true }` option:

```jsx
var Hello = createReactClass({
Expand Down Expand Up @@ -66,7 +78,7 @@ export default function Hello({ name }) {
Hello.displayName = 'Hello';
```

Examples of **incorrect** code for this rule:
Examples of **incorrect** code for `{ ignoreTranspilerName: true }` option:

```jsx
var Hello = createReactClass({
Expand Down