feat: Moments: your personal photo journal, now available in Labs (#2079)

This commit is contained in:
Mo
2022-12-02 08:41:21 -06:00
committed by GitHub
parent 621bf1b810
commit 29368c51b8
18 changed files with 541 additions and 10 deletions

View File

@@ -0,0 +1,19 @@
import { useApplication } from '@/Components/ApplicationProvider'
import { ApplicationEvent, PrefKey } from '@standardnotes/snjs'
import { useEffect, useState } from 'react'
export default function usePreference<T>(preference: PrefKey) {
const application = useApplication()
const [value, setValue] = useState<T>(application.getPreference(preference) as T)
useEffect(() => {
return application.addEventObserver(async () => {
const latestValue = application.getPreference(preference)
setValue(latestValue as T)
}, ApplicationEvent.PreferencesChanged)
}, [application, preference])
return value
}