Skip to content

useReactFunctionComponentDefinition

biome.json
{
"linter": {
"rules": {
"nursery": {
"useReactFunctionComponentDefinition": "error"
}
}
}
}

Enforce a specific function type for React function components.

This rule keeps function component definitions consistent. By default, named components must be written as function declarations.

const MyComponent = (props) => {
return <div>{props.name}</div>;
};
code-block.jsx:1:7 lint/nursery/useReactFunctionComponentDefinition  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━

The React component MyComponent is defined as an arrow function.

> 1 │ const MyComponent = (props) => {
^^^^^^^^^^^
2 │ return <div>{props.name}</div>;
3 │ };

Mixing component definition styles makes component declarations harder to scan.

Rewrite this component as a function declaration or configure `namedComponents` to allow an arrow function.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

Unsafe fix: Use a function declaration for this component.

1 - const·MyComponent·=·(props)·=>·{
1+ function·MyComponent·(props)·{
2 2 return <div>{props.name}</div>;
3 - };
3+ }
4 4

function MyComponent(props) {
return <div>{props.name}</div>;
}

The function style to enforce for named React components. Accepted values are:

  • "functionDeclaration" (default): Enforce function declarations.
  • "functionExpression": Enforce function expressions assigned to component bindings.
  • "arrowFunction": Enforce arrow functions assigned to component bindings.
biome.json
{
"linter": {
"rules": {
"nursery": {
"useReactFunctionComponentDefinition": {
"options": {
"namedComponents": "functionDeclaration"
}
}
}
}
}
}
const MyComponent = (props) => {
return <div>{props.name}</div>;
};
code-block.jsx:1:7 lint/nursery/useReactFunctionComponentDefinition  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━

The React component MyComponent is defined as an arrow function.

> 1 │ const MyComponent = (props) => {
^^^^^^^^^^^
2 │ return <div>{props.name}</div>;
3 │ };

Mixing component definition styles makes component declarations harder to scan.

Rewrite this component as a function declaration or configure `namedComponents` to allow an arrow function.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

Unsafe fix: Use a function declaration for this component.

1 - const·MyComponent·=·(props)·=>·{
1+ function·MyComponent·(props)·{
2 2 return <div>{props.name}</div>;
3 - };
3+ }
4 4

function MyComponent(props) {
return <div>{props.name}</div>;
}
biome.json
{
"linter": {
"rules": {
"nursery": {
"useReactFunctionComponentDefinition": {
"options": {
"namedComponents": "functionExpression"
}
}
}
}
}
}
function MyComponent(props) {
return <div>{props.name}</div>;
}
code-block.jsx:1:10 lint/nursery/useReactFunctionComponentDefinition  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━

The React component MyComponent is defined as a function declaration.

> 1 │ function MyComponent(props) {
^^^^^^^^^^^
2 │ return <div>{props.name}</div>;
3 │ }

Mixing component definition styles makes component declarations harder to scan.

Rewrite this component as a function expression or configure `namedComponents` to allow a function declaration.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

Unsafe fix: Use a function expression for this component.

1 - function·MyComponent(props)·{
1+ const·MyComponent·=·function·(props)·{
2 2 return <div>{props.name}</div>;
3 - }
3+ };
4 4

const MyComponent = (props) => {
return <div>{props.name}</div>;
};
code-block.jsx:1:7 lint/nursery/useReactFunctionComponentDefinition  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━

The React component MyComponent is defined as an arrow function.

> 1 │ const MyComponent = (props) => {
^^^^^^^^^^^
2 │ return <div>{props.name}</div>;
3 │ };

Mixing component definition styles makes component declarations harder to scan.

Rewrite this component as a function expression or configure `namedComponents` to allow an arrow function.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

Unsafe fix: Use a function expression for this component.

1 - const·MyComponent·=·(props)·=>·{
1+ const·MyComponent·=·function·(props)·{
2 2 return <div>{props.name}</div>;
3 3 };

const MyComponent = function (props) {
return <div>{props.name}</div>;
};
biome.json
{
"linter": {
"rules": {
"nursery": {
"useReactFunctionComponentDefinition": {
"options": {
"namedComponents": "arrowFunction"
}
}
}
}
}
}
function MyComponent(props) {
return <div>{props.name}</div>;
}
code-block.jsx:1:10 lint/nursery/useReactFunctionComponentDefinition  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━

The React component MyComponent is defined as a function declaration.

> 1 │ function MyComponent(props) {
^^^^^^^^^^^
2 │ return <div>{props.name}</div>;
3 │ }

Mixing component definition styles makes component declarations harder to scan.

Rewrite this component as an arrow function or configure `namedComponents` to allow a function declaration.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

Unsafe fix: Use an arrow function for this component.

1 - function·MyComponent(props)·{
1+ const·MyComponent·=·(props)·=>·{
2 2 return <div>{props.name}</div>;
3 - }
3+ };
4 4

const MyComponent = function (props) {
return <div>{props.name}</div>;
};
code-block.jsx:1:7 lint/nursery/useReactFunctionComponentDefinition  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━

The React component MyComponent is defined as a function expression.

> 1 │ const MyComponent = function (props) {
^^^^^^^^^^^
2 │ return <div>{props.name}</div>;
3 │ };

Mixing component definition styles makes component declarations harder to scan.

Rewrite this component as an arrow function or configure `namedComponents` to allow a function expression.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

Unsafe fix: Use an arrow function for this component.

1 - const·MyComponent·=·function·(props)·{
1+ const·MyComponent·=·(props)·=>·{
2 2 return <div>{props.name}</div>;
3 3 };

const MyComponent = (props) => {
return <div>{props.name}</div>;
};