Skip to content

Commit d8cc259

Browse files
committed
invoke listeners in render, follows dai-shi/reactive-react-redux#31
1 parent 2a27722 commit d8cc259

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Change Log
22

33
## [Unreleased]
4+
### Changed
5+
- No useLayoutEffect for invoking listeners (which leads de-opt sync mode)
46

57
## [0.2.0] - 2019-07-07
68
### Changed

src/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ const identity = x => x;
1212
const CONTEXT_LISTENERS = Symbol('CONTEXT_LISTENERS');
1313

1414
const createProvider = (OrigProvider, listeners) => React.memo(({ value, children }) => {
15-
React.useLayoutEffect(() => {
16-
listeners.forEach(listener => listener(value));
17-
}, [value]);
15+
// we call listeners in render intentionally.
16+
// listeners are not technically pure, but
17+
// otherwise we can't get benefits from concurrent mode.
18+
// we make sure to work with double or more invocation of listeners.
19+
listeners.forEach(listener => listener(value));
1820
return React.createElement(OrigProvider, { value }, children);
1921
});
2022

@@ -56,7 +58,6 @@ export const useContextSelector = (context, selector) => {
5658
} catch (e) {
5759
// ignored (stale props or some other reason)
5860
}
59-
ref.current.value = nextValue;
6061
forceUpdate();
6162
};
6263
listeners.add(callback);

0 commit comments

Comments
 (0)