admin管理员组文章数量:1287145
I am using TextField of material UI as a ponent.
import { FieldProps, getIn } from "formik";
import React from "react";
export const FormTextField: React.FC<FieldProps & TextFieldProps> = ({
error,
helperText,
field,
form,
...rest
}) => {
const isTouched = getIn(form.touched, field.name);
const errorMessage = getIn(form.errors, field.name);
return (
<TextField
variant="outlined"
fullWidth
error={error ?? Boolean(isTouched && errorMessage)}
helperText={
helperText ?? (isTouched && errorMessage ? errorMessage : undefined)
}
{...rest}
{...field}
/>
);
};
When I run the pnpm lint then it is throwing me this error:
Error: Function ponent is not a function declaration (react/function-ponent-definition)
I want to use this ponent but can't find any solution to resolve it. What could be its solution? Kindly help me. Thanks
I am using TextField of material UI as a ponent.
import { FieldProps, getIn } from "formik";
import React from "react";
export const FormTextField: React.FC<FieldProps & TextFieldProps> = ({
error,
helperText,
field,
form,
...rest
}) => {
const isTouched = getIn(form.touched, field.name);
const errorMessage = getIn(form.errors, field.name);
return (
<TextField
variant="outlined"
fullWidth
error={error ?? Boolean(isTouched && errorMessage)}
helperText={
helperText ?? (isTouched && errorMessage ? errorMessage : undefined)
}
{...rest}
{...field}
/>
);
};
When I run the pnpm lint then it is throwing me this error:
Error: Function ponent is not a function declaration (react/function-ponent-definition)
I want to use this ponent but can't find any solution to resolve it. What could be its solution? Kindly help me. Thanks
Share Improve this question asked Sep 15, 2022 at 17:44 JohnJohn 3231 gold badge3 silver badges10 bronze badges 3- did you try declaring the parameter in a var statement? – Hogan Commented Sep 15, 2022 at 17:49
- error is ing due to function ponent. var doesn't work for it. – John Commented Sep 15, 2022 at 17:50
-
make it function declaration,
export function FormTextField(...){...}
– norbekoff Commented Sep 15, 2022 at 17:52
1 Answer
Reset to default 6Read the documentation for that linting rule: https://github./jsx-eslint/eslint-plugin-react/blob/master/docs/rules/function-ponent-definition.md
It's telling you that it expects ponents to be declared as function declarations.
That means this:
export function FormTextField<FieldProps & TextFieldProps>({ //...
In fact, it look like this rule is automatically fixable. If you run pnpm lint --fix
this will probably resolve itself.
本文标签: javascriptError Function component is not a function declarationStack Overflow
版权声明:本文标题:javascript - Error: Function component is not a function declaration - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741298657a2370960.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论