Skip to content

Commit

Permalink
refactor: avoid needing eslint disable
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiVandivier committed Jul 18, 2024
1 parent 52057eb commit 79d0b0e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
1 change: 0 additions & 1 deletion services/offline/src/lib/cacheable-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export function useCacheableSection(id: string): CacheableSectionControls {
removeRecordingState()
}
}
// todo: avoid dependency on recordingState
}, []) // eslint-disable-line react-hooks/exhaustive-deps

const onRecordingStarted = useCallback(() => {
Expand Down
24 changes: 13 additions & 11 deletions services/offline/src/lib/global-state-service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,24 @@ export const useGlobalState = (
// NEW: deep equality check before updating
const callback = (state: any) => {
const newSelectedState = selector(state)
// Second condition handles case where a selected object gets
// deleted, but state does not update
if (
!isEqual(selectedState, newSelectedState) ||
selectedState === undefined
) {
setSelectedState(newSelectedState)
}
// Use this form to avoid having `selectedState` as a dep in here
setSelectedState((currentSelectedState: any) => {
// Second condition handles case where a selected object gets
// deleted, but state does not update
if (
!isEqual(currentSelectedState, newSelectedState) ||
currentSelectedState === undefined
) {
return newSelectedState
}
return currentSelectedState
})
}
store.subscribe(callback)
// Make sure to update state when selector changes
callback(store.getState())
return () => store.unsubscribe(callback)
// todo: refactor to use setSelectedState(selectedState => ...) to avoid
// requiring selectedState as a dependency
}, [store, selector]) /* eslint-disable-line react-hooks/exhaustive-deps */
}, [store, selector])

return useMemo(
() => [selectedState, store.mutate],
Expand Down

0 comments on commit 79d0b0e

Please sign in to comment.