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
"Component definition is missing display name" with React.createElement #597
Comments
A function that returns jsx (ie, that generates a You're also correct that any solution to #512 would also work here. However, for now I'd recommend just disabling the rule on that line/file. |
It seems this is also triggered when using thunks that return ReactElements (...which look very similar to a SFC, but are not quite the same). Here's an example, where <span>
{t('String with %(a:replacement)', {
a: text => <a href='/'>{text}</a> /* react/display-name warns here */
})}
</span> |
While such functions may be used as components (i.e. passed as the first arg to I'd say we can close this issue as a dup of #512 |
I agree this is a duplicate of #512. |
//warn
const wrapWithToastProvider = Comp => props => (
<ToastProvider>
<Comp {...props} />
</ToastProvider>
);
//warn
function wrapWithToastProvider(Comp) {
return function (props) {
return (
<ToastProvider>
<Comp {...props} />
</ToastProvider>
);
};
} Any help? |
@sturmenta neither of those is a named function: function wrapWithToastProvider(Comp) {
return function WrappedWithToast(props) {
return (
<ToastProvider>
<Comp {...props} />
</ToastProvider>
);
};
} |
@ljharb is it possible to do something similar with arrow functions?
I thought that it should automatically pass |
@Nikolai-S absolutely not; the language’s inference will never extend beyond your outer HOC. If you want your components to reliably have names, do not use arrow functions for them, ever. |
"react/display-name": "off" |
The example in the original post here: var Utils = {
label: function(settings) {
return <span className={'label ' + settings.klass}>{ settings.text }</span>;
},
}; Is in fact a false positive of this rule, since the display name of the function is correctly set to the key in literal objects since ES6: https://2ality.com/2015/09/function-names-es6.html For example: const x = { foo: () => {} }
x.foo.name // === "foo" even though the function is an anonymous lambda |
@phiresky you have to enable ignoreTranspilerNames to be able to rely on inference (which i don’t suggest doing) |
Ah, I didn't see there was a configurable option for that (link). Docs don't listing anything about it not being recommended. Why would you not suggest it? |
Function name inference is specified, but not intuitive and will not always apply when one thinks it does. It's far, far better for debuggability to always and only use explicit names. |
Hello
eslint-plugin-react
maintainers, your plugins has surely been of great help so far :)But I recently had problems with
react/display-name
rule, I have several functions that returnReact.createElement
instances on my code, and they seem to be triggeringreact/display-name
rule, even though I'm not creating aComponent
.I have isolated the problem on the following code:
The minimal
.eslintrc
code I need to make that work is:As I am seeing this, the
Utils.label
function should not be triggeringreact/display-name
rule. A<span></span>
instance will generate aReact.createElement
instance, so no displayName should be required for it, right?Edit:
This may be related to: #512
The text was updated successfully, but these errors were encountered: