Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane Osbourne committed Oct 10, 2024
1 parent 01108d2 commit d02f2dd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ export function Body ({ trackerCompanies, send, ui }) {
)
}

/**
* Use this when rendered within a widget list.
*
* It reaches out to access this widget's global visibility, and chooses
* whether to incur the side effects (data fetching).
*/
export function PrivacyStatsCustomized () {
const { visibility } = useVisibility()
if (visibility === 'hidden') {
Expand All @@ -158,6 +164,18 @@ export function PrivacyStatsCustomized () {
)
}

/**
* Use this when you want to render the UI from a context where
* the service is available.
*
* for example:
*
* ```jsx
* <PrivacyStatsProvider>
* <PrivacyStatsConsumer />
* </PrivacyStatsProvider>
* ```
*/
export function PrivacyStatsConsumer () {
const { state, toggle } = useContext(PrivacyStatsContext)
if (state.status === 'ready') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,12 @@ function useConfigSubscription ({ dispatch, service }) {

useEffect(() => {
if (!service.current) return console.warn('could not access service')
const unsub2 = service.current.onConfig((data) => {
const unsub = service.current.onConfig((data) => {
const animate = !isReducedMotion && data.source === 'manual'
dispatch({ kind: 'config', config: data.data, animate })
})
return () => {
unsub2()
unsub()
}
}, [service, isReducedMotion])

Expand Down

0 comments on commit d02f2dd

Please sign in to comment.