Skip to main content
GoodFirstPicks
DashboardIssuesReposLeaderboard

GoodFirstPicks by Leaveitblank © 2026

CreatorRequest a RepoPrivacy PolicyTerms of Service
Bug: The ESLint react-hooks/preserve-manual-memoization rule warns against optional chaining operator | GoodFirstPicks

Bug: The ESLint react-hooks/preserve-manual-memoization rule warns against optional chaining operator

facebook/react 2 comments 1mo ago
View on GitHub
mediumopenScope: somewhat clearSkill match: maybeReactJavaScriptTypeScript

Why this is a good first issue

The issue involves modifying ESLint rule behavior to handle optional chaining in dependency arrays.

AI Summary

The issue reports a false positive warning from the ESLint react-hooks/preserve-manual-memoization rule when using optional chaining in dependency arrays. The fix would require updating the rule's dependency comparison logic to account for optional chaining patterns. The main challenge is ensuring the change doesn't introduce new false negatives while maintaining the rule's safety guarantees.

Issue Description

eslint-plugin-react-hooks version: 7.0.1

Steps To Reproduce

const Test = ({ obj }) => {
    const onClick = useCallback(() => {
        if (obj?.id) {
            console.log(obj.id);
        }
    }, [obj?.id]);

    return (
        <button onClick={onClick}>
            Hello
        </button>
    );
};

The current behavior

Compilation Skipped: Existing memoization could not be preserved

React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `obj`, but the source dependencies were [obj?.id]. Inferred less specific property than source.

The expected behavior

No errors

This can be fixed in several trivial ways:

  1. Use obj?.id in all places
  2. Introduce the variable:
const onClick = useCallback(() => {
    const id = obj?.id;
    if (id) {
        console.log(id);
    }
}, [obj?.id]);

GitHub Labels

Status: Unconfirmed

Want to work on this?

Claim this issue to let others know you're working on it. You'll earn 10 points when you complete it!

Risk Flags

  • requires understanding of React Compiler internals
  • potential edge cases with optional chaining
Loading labels...

Details

Points10 pts
Difficultymedium
Scopesomewhat clear
Skill Matchmaybe
Test Focusedno