Skip to content

Commit

Permalink
Context consumer unmounting perf
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Oct 4, 2024
1 parent 87f7efa commit 4e84f83
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/create-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ export function createContext(defaultValue, contextId) {
let old = c.componentWillUnmount;
c.componentWillUnmount = () => {
if (subs) {
subs.splice(subs.indexOf(c), 1);
if (subs.length === 1) {
subs = [];
} else {
subs[subs.indexOf(c)] = subs.pop();
}
}
if (old) old.call(c);
};
Expand Down

0 comments on commit 4e84f83

Please sign in to comment.