Skip to content

eslint-plugin-react-hooks: lint rule to enforce that useMemo returns a value #25379

@JoshuaKGoldberg

Description

@JoshuaKGoldberg

Nothing prevents developers from calling useMemo without a return:

import { useMemo } from "react";

useMemo(() => {
    console.log("Yippee!");
}, []);

[TypeScript playground showing no errors]

Calling useMemo without a returned value is somewhat equivalent to calling useEffect without a returned value. Judging by the few times I've seen it happen, it's likely a case of a developer either confusing the two hooks or forgetting to return the memoized value.

Suggestion: can we add a lint rule to flag useMemo calls that don't definitely return a value? It could have a suggestion fixer to switch to useEffect.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions