internal: incomplete vault systems behind feature flag (#2340)
This commit is contained in:
29
packages/web/src/javascripts/Hooks/useItem.ts
Normal file
29
packages/web/src/javascripts/Hooks/useItem.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { useApplication } from '@/Components/ApplicationProvider'
|
||||
import { DecryptedItemInterface, LiveItem } from '@standardnotes/snjs'
|
||||
import { useEffect, useState } from 'react'
|
||||
|
||||
const useItem = <T extends DecryptedItemInterface>(uuid: string | undefined) => {
|
||||
const application = useApplication()
|
||||
|
||||
const [item, setItem] = useState<T>()
|
||||
|
||||
useEffect(() => {
|
||||
if (!uuid) {
|
||||
return
|
||||
}
|
||||
|
||||
const live = new LiveItem<T>(uuid, application, (item) => {
|
||||
setItem(item)
|
||||
})
|
||||
|
||||
return () => live.deinit()
|
||||
}, [uuid, application])
|
||||
|
||||
if (!uuid) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
return item
|
||||
}
|
||||
|
||||
export default useItem
|
||||
Reference in New Issue
Block a user