Skip to content

Rename useMemo _callback to _factory (+0 B)#2131

Merged
andrewiggins merged 2 commits into
masterfrom
fix/rename-callback
Nov 15, 2019
Merged

Rename useMemo _callback to _factory (+0 B)#2131
andrewiggins merged 2 commits into
masterfrom
fix/rename-callback

Conversation

@andrewiggins

Copy link
Copy Markdown
Member

While re-reading this code, the name _callback kept tripping me up because I thought it was something that needed to be invoked after some asynchronous event. But then I realized I was just misunderstanding this parameter. So I thought I'd rename it to something that more explicitly states the intention of what this parameter is: a factory that produces a value we remember.

This PR also includes an improvement to useMemo types I copied from DefinitelyTyped (link in comments)

Thoughts?

Comment thread hooks/src/index.d.ts
*/
export function useMemo<T>(factory: () => T, inputs?: Inputs): T;
// for `inputs`, allow undefined, but don't make it optional as that is very likely a mistake
export function useMemo<T>(factory: () => T, inputs: Inputs | undefined): T;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied this from the react types for useMemo

@coveralls

coveralls commented Nov 15, 2019

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.1%) to 100.0% when pulling 38ab820 on fix/rename-callback into 6b5abcb on master.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants