Skip to content

Commit

Permalink
πŸ‘ŒπŸ“ [devext] add comments to the useSettings hook
Browse files Browse the repository at this point in the history
  • Loading branch information
BenoitZugmeyer committed May 17, 2023
1 parent 8135d2f commit 45fb402
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions developer-extension/src/panel/hooks/useSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,18 @@ function setSetting<Name extends keyof Settings>(name: Name, value: Settings[Nam
}

export function useSettings() {
// If we don't have settings yet, it means that we are still loading them from the storage. Throw
// the promise so it'll be caught by the Suspense boundary.
if (!settings) {
throw storageLoadingPromise
}

// We want to have a single 'settings' object shared between all components (it's easier to have
// a single source of truth and simplifies persistence implementation). Usually, we would use
// something like redux or one of the many other alternatives. Since we have a single use-case in
// this project, let's implement a shared state manually by forcing an update when the 'settings'
// object changes.

// https://legacy.reactjs.org/docs/hooks-faq.html#is-there-something-like-forceupdate
const [, forceUpdate] = useReducer((x: number) => x + 1, 0)

Expand Down

0 comments on commit 45fb402

Please sign in to comment.