Skip to content

useReactNamingConvention (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"useReactNamingConvention": "error"
}
}
}
}

Enforces naming conventions for React createContext, useId, and useRef.

This rule checks the name that receives the result of each React API call. Consistent names make the purpose of the value clear at a glance:

  • A value assigned from createContext must be a valid component name (PascalCase) with the suffix Context, for example ThemeContext.
  • A value assigned from useId must be named id or a valid camelCase name ending with Id, for example myId.
  • A value assigned from useRef must be named ref or a valid camelCase name ending with Ref, for example myRef.
import { createContext } from "react";
const theme = createContext("");
code-block.jsx:2:7 lint/nursery/useReactNamingConvention ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This React context is not following the context naming convention.

1 │ import { createContext } from "react";
> 2 │ const theme = createContext("");
│ ^^^^^
3 │

ℹ React contexts have to follow a naming convention to make them more recognizable across the codebase.

ℹ Rename it to a PascalCase name ending with Context, such as ThemeContext.

ℹ 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.

import { useId } from "react";
const randomString = useId();
code-block.jsx:2:7 lint/nursery/useReactNamingConvention ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This React id is not following the id naming convention.

1 │ import { useId } from "react";
> 2 │ const randomString = useId();
│ ^^^^^^^^^^^^
3 │

ℹ React ids have to follow a naming convention to make them more recognizable across the codebase.

ℹ Rename the value to id or a name ending with Id, such as myId.

ℹ 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.

import { useRef } from "react";
const node = useRef(null);
code-block.jsx:2:7 lint/nursery/useReactNamingConvention ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This React ref is not following the ref naming convention.

1 │ import { useRef } from "react";
> 2 │ const node = useRef(null);
│ ^^^^
3 │

ℹ React refs have to follow a naming convention to make them more recognizable across the codebase.

ℹ Rename the value to ref or a name ending with Ref, such as myRef.

ℹ 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.

import { createContext } from "react";
const ThemeContext = createContext("");
import { useId } from "react";
const myId = useId();
import { useRef } from "react";
const myRef = useRef(null);