Add to settings, abstract state, not updating in tab

This commit is contained in:
Eric Bailey
2024-12-11 18:03:25 -06:00
parent 55b573a35a
commit e3d110207e
3 changed files with 52 additions and 19 deletions
+28
View File
@@ -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
}