Skip to content

Commit

Permalink
Fix failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
poteto committed Oct 19, 2022
1 parent a4c10ec commit 1730a42
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 7 additions & 3 deletions packages/react-reconciler/src/ReactFiberHooks.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -1934,7 +1934,7 @@ function useEventImpl<Args, Return, F: (...Array<Args>) => Return>(
}
}

function wrapEventFunction<Args, Return, F: (...Array<Args>) => Return>(
export function wrapEventFunction<Args, Return, F: (...Array<Args>) => Return>(
callback: F,
): EventFunctionWrapper<Args, Return, F> {
const eventFn: EventFunctionWrapper<Args, Return, F> = function eventFn() {
Expand All @@ -1953,17 +1953,21 @@ function wrapEventFunction<Args, Return, F: (...Array<Args>) => Return>(
function mountEvent<Args, Return, F: (...Array<Args>) => Return>(
callback: F,
): EventFunctionWrapper<Args, Return, F> {
const hook = mountWorkInProgressHook();
const eventFn = wrapEventFunction(callback);
hook.memoizedState = eventFn;
useEventImpl(eventFn, callback);
return eventFn;
}

function updateEvent<Args, Return, F: (...Array<Args>) => Return>(
callback: F,
): EventFunctionWrapper<Args, Return, F> {
const eventFn = wrapEventFunction(callback);
const hook = updateWorkInProgressHook();
const eventFn = hook.memoizedState;
useEventImpl(eventFn, callback);
return eventFn;
// Always return a new function
return wrapEventFunction(callback);
}

function mountInsertionEffect(
Expand Down
10 changes: 7 additions & 3 deletions packages/react-reconciler/src/ReactFiberHooks.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -1934,7 +1934,7 @@ function useEventImpl<Args, Return, F: (...Array<Args>) => Return>(
}
}

function wrapEventFunction<Args, Return, F: (...Array<Args>) => Return>(
export function wrapEventFunction<Args, Return, F: (...Array<Args>) => Return>(
callback: F,
): EventFunctionWrapper<Args, Return, F> {
const eventFn: EventFunctionWrapper<Args, Return, F> = function eventFn() {
Expand All @@ -1953,17 +1953,21 @@ function wrapEventFunction<Args, Return, F: (...Array<Args>) => Return>(
function mountEvent<Args, Return, F: (...Array<Args>) => Return>(
callback: F,
): EventFunctionWrapper<Args, Return, F> {
const hook = mountWorkInProgressHook();
const eventFn = wrapEventFunction(callback);
hook.memoizedState = eventFn;
useEventImpl(eventFn, callback);
return eventFn;
}

function updateEvent<Args, Return, F: (...Array<Args>) => Return>(
callback: F,
): EventFunctionWrapper<Args, Return, F> {
const eventFn = wrapEventFunction(callback);
const hook = updateWorkInProgressHook();
const eventFn = hook.memoizedState;
useEventImpl(eventFn, callback);
return eventFn;
// Always return a new function
return wrapEventFunction(callback);
}

function mountInsertionEffect(
Expand Down

0 comments on commit 1730a42

Please sign in to comment.