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 rules checks the variable a React API hook is assigned to and enforces a name convention to make the intent of a value obvious 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);