Skip to content

Commit

Permalink
Add a __key field to create functions to check identity
Browse files Browse the repository at this point in the history
  • Loading branch information
trueadm committed Nov 8, 2018
1 parent 7b17a03 commit 3a5b065
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/react-reconciler/src/ReactFiberHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,20 @@ function useEffectImpl(fiberEffectTag, hookEffectTag, create, inputs): void {
currentlyRenderingFiber = resolveCurrentlyRenderingFiber();
workInProgressHook = createWorkInProgressHook();

let nextInputs = inputs !== undefined && inputs !== null ? inputs : [];
let nextInputs;
if (inputs !== undefined && inputs !== null) {
nextInputs = inputs;
} else {
// Rather than storing the create function in the nextInputs, which might
// cause memory issues due to shared context of the retained closure. We
// can instead add field called "__key" and assign a symbol to the field.
// We then store this symbol and use it as a key instead of the function.
// Note: This will require the ES2015 Symbol polyfill.
if (create.__key === undefined) {
create.__key = Symbol();
}
nextInputs = [create.__key];
}
let destroy = null;
if (currentHook !== null) {
const prevEffect = currentHook.memoizedState;
Expand Down

0 comments on commit 3a5b065

Please sign in to comment.