Add to settings, abstract state, not updating in tab
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import React from 'react'
|
||||
|
||||
import * as persisted from '#/state/persisted'
|
||||
|
||||
// TODO only updates in other tabs, not current one
|
||||
export function useTrendingTopicsSidebarSetting() {
|
||||
const [_show, setShow] = React.useState(
|
||||
() => !persisted.get('hideSidebarTrendingTopics'),
|
||||
)
|
||||
|
||||
const set = React.useCallback(
|
||||
(show: boolean) => {
|
||||
setShow(show)
|
||||
persisted.write('hideSidebarTrendingTopics', !show)
|
||||
},
|
||||
[setShow],
|
||||
)
|
||||
|
||||
// persisted.write('hideSidebarTrendingTopics', undefined)
|
||||
|
||||
React.useEffect(() => {
|
||||
return persisted.onUpdate('hideSidebarTrendingTopics', value => {
|
||||
setShow(!value)
|
||||
})
|
||||
}, [setShow])
|
||||
|
||||
return [_show, set] as const
|
||||
}
|
||||
Reference in New Issue
Block a user