Skip to content

Commit c4a1878

Browse files
author
james
committed
Bug fix.
1 parent df41a09 commit c4a1878

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/hooks/useSharedState.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ export class SharedState {
88

99
watch(watcher) {
1010
this.watchers.push(watcher);
11-
return this.watchers.length - 1;
1211
}
1312

14-
removeWatcher(index) {
13+
removeWatcher(watcher) {
14+
const index = this.watchers.indexOf(watcher);
1515
this.watchers.splice(index, 1);
1616
}
1717

@@ -77,8 +77,8 @@ export class SharedPersistedState extends SharedState {
7777
export function useSharedState(sharedState) {
7878
const [value, setValue] = useState(sharedState.value);
7979
useEffect(() => {
80-
const watcherIndex = sharedState.watch(setValue);
81-
return () => sharedState.removeWatcher(watcherIndex);
80+
sharedState.watch(setValue);
81+
return () => sharedState.removeWatcher(setValue);
8282
}, [sharedState]);
8383
return [value, newValue => sharedState.setValue(newValue)];
8484
}

0 commit comments

Comments
 (0)