react-doctor/no-create-ref-in-function-component
createRef in function component
- Category: Bugs
- Severity: warn
- Source:
oxlint-plugin-react-doctor - Framework: global
- Enabled when: react
- Default: Enabled
Validation prompt
Use this to decide whether a fired diagnostic is real or a false positive.
Confirm the reported code matches createRef in function component. Check the framework context and diagnostic message before suppressing it.
Fix prompt
Use this once validation confirms the diagnostic is real.
Replace createRef() with the useRef() hook inside function components and hooks. createRef is only for class components.
Related rules
More Bugs rules from the rules reference:
react-doctor/no-create-store-in-render: Hoist the store/atom/observable construction to module scope: const store = create(...) outside the component.react-doctor/no-danger-with-children: Use either children or dangerouslySetInnerHTML on an element, never both.react-doctor/no-derived-state: Disallow storing derived state in an effect.react-doctor/no-derived-state-effect: For derived state, compute inline: `const x = fn(dep)`. For state resets on prop change, use a key prop: `<Component key={prop} />`. See https://react.dev/learn/you-might-not-need-an-effectreact-doctor/no-derived-useState: Remove useState and compute the value inline: `const value = transform(propName)`