Commit c4a1878 james
committed
1 parent df41a09 commit c4a1878 Copy full SHA for c4a1878
File tree 1 file changed +4
-4
lines changed
1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -8,10 +8,10 @@ export class SharedState {
8
8
9
9
watch ( watcher ) {
10
10
this . watchers . push ( watcher ) ;
11
- return this . watchers . length - 1 ;
12
11
}
13
12
14
- removeWatcher ( index ) {
13
+ removeWatcher ( watcher ) {
14
+ const index = this . watchers . indexOf ( watcher ) ;
15
15
this . watchers . splice ( index , 1 ) ;
16
16
}
17
17
@@ -77,8 +77,8 @@ export class SharedPersistedState extends SharedState {
77
77
export function useSharedState ( sharedState ) {
78
78
const [ value , setValue ] = useState ( sharedState . value ) ;
79
79
useEffect ( ( ) => {
80
- const watcherIndex = sharedState . watch ( setValue ) ;
81
- return ( ) => sharedState . removeWatcher ( watcherIndex ) ;
80
+ sharedState . watch ( setValue ) ;
81
+ return ( ) => sharedState . removeWatcher ( setValue ) ;
82
82
} , [ sharedState ] ) ;
83
83
return [ value , newValue => sharedState . setValue ( newValue ) ] ;
84
84
}
You can’t perform that action at this time.
0 commit comments