Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusing error when passing non-function to useMemo #16589

Open
aweary opened this issue Aug 27, 2019 · 6 comments
Open

Confusing error when passing non-function to useMemo #16589

aweary opened this issue Aug 27, 2019 · 6 comments

Comments

@aweary
Copy link
Contributor

aweary commented Aug 27, 2019

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.

@threepointone
Copy link
Contributor

Huh. This is usually caught by flow/typescript, but I can see why it might be confusing without a type system. Do you believe this is a common problem? If so, maybe a DEV warning would be good.

@Tevinthuku
Copy link

@threepointone , If you resolve to have a dev warning for this, I could work on that

@duanebester
Copy link

@aweary I have an incoming PR for this

@caspercasanova
Copy link

Why is this still open?

@jeanpierrecarvalho
Copy link

Why is this still open?

@duanebester

@duanebester
Copy link

Add DEV warning for when a non-function is passed to useMemo #17529

No one ever approved my PR, so I closed it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants