useReactNamingConvention (JavaScript)
Language JavaScript (and super languages)
Summary
Section titled “Summary”- Rule available since:
v2.5.12 - Diagnostic Category:
lint/nursery/useReactNamingConvention - This rule doesn’t have a fix.
- The default severity of this rule is information.
- This rule belongs to the following domains:
- Sources:
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "useReactNamingConvention": "error" } } }}Description
Section titled “Description”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
createContextmust be a valid component name (PascalCase) with the suffixContext, for exampleThemeContext. - A value assigned from
useIdmust be namedidor a valid camelCase name ending withId, for examplemyId. - A value assigned from
useRefmust be namedrefor a valid camelCase name ending withRef, for examplemyRef.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”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);Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.