Skip to content

Confusing error when passing non-function to useMemo #16589

@aweary

Description

@aweary

Example.

When passing something like an object to useMemo the error isn't very helpful.

TypeError: nextCreate is not a function
    at mountMemo (https://grhhp.csb.app/node_modules/react-dom/cjs/react-dom.development.js:13459:19)
    ...

Most developers wont know what nextCreate is, and passing an object to useMemo doesn't seem obviously wrong at first. We could add a typeof check that throws a better error, but maybe that's too much overhead? At the very least we could add a DEV warning with more helpful guidance.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions