Skip to content

Commit

Permalink
Merge 38ab820 into 6b5abcb
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewiggins committed Nov 15, 2019
2 parents 6b5abcb + 38ab820 commit a919c4f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion debug/src/debug.js
Expand Up @@ -273,7 +273,7 @@ export function initDebug() {
let hooks = component.__hooks;
if (Array.isArray(hooks._list)) {
hooks._list.forEach(hook => {
if (hook._callback && (!hook._args || !Array.isArray(hook._args))) {
if (hook._factory && (!hook._args || !Array.isArray(hook._args))) {
let componentName = getDisplayName(vnode);
console.warn(
`In ${componentName} you are calling useMemo/useCallback without passing arguments.\n` +
Expand Down
3 changes: 2 additions & 1 deletion hooks/src/index.d.ts
Expand Up @@ -106,7 +106,8 @@ export function useCallback<T extends Function>(callback: T, inputs: Inputs): T;
* This optimization helps to avoid expensive calculations on every render.
* If no array is provided, a new value will be computed whenever a new function instance is passed as the first argument.
*/
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;

/**
* Returns the current context value, as given by the nearest context provider for the given context.
Expand Down
8 changes: 4 additions & 4 deletions hooks/src/index.js
Expand Up @@ -174,16 +174,16 @@ export function useImperativeHandle(ref, createHandle, args) {
}

/**
* @param {() => any} callback
* @param {() => any} factory
* @param {any[]} args
*/
export function useMemo(callback, args) {
export function useMemo(factory, args) {
/** @type {import('./internal').MemoHookState} */
const state = getHookState(currentIndex++);
if (argsChanged(state._args, args)) {
state._args = args;
state._callback = callback;
return (state._value = callback());
state._factory = factory;
return (state._value = factory());
}

return state._value;
Expand Down
2 changes: 1 addition & 1 deletion hooks/src/internal.d.ts
Expand Up @@ -46,7 +46,7 @@ export interface EffectHookState {
export interface MemoHookState {
_value?: any;
_args?: any[];
_callback?: () => any;
_factory?: () => any;
}

export interface ReducerHookState {
Expand Down

0 comments on commit a919c4f

Please sign in to comment.