Skip to content

Commit

Permalink
move useStore out of core
Browse files Browse the repository at this point in the history
#5443 (comment)
(cherry picked from commit 00070c870f76876aca92e97f410f8b52085191bc)
  • Loading branch information
mifi committed Dec 2, 2024
1 parent afd4bef commit 3d88f05
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 29 deletions.
28 changes: 0 additions & 28 deletions packages/@uppy/core/src/useStore.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { h } from 'preact'
import { useCallback, useEffect, useRef, useState } from 'preact/hooks'

import type { Uppy } from '@uppy/core'
import useStore from '@uppy/core/lib/useStore.js'
import type { AsyncStore } from '@uppy/core/lib/Uppy.js'

import {
Expand All @@ -19,6 +18,31 @@ import {
import AuthView from '../ProviderView/AuthView.js'
import { GoogleDriveIcon, GooglePhotosIcon } from './icons.js'

function useStore(
store: AsyncStore,
key: string,
): [string | undefined | null, (v: string | null) => Promise<void>] {
const [value, setValueState] = useState<string | null | undefined>()
useEffect(() => {
;(async () => {
setValueState(await store.getItem(key))
})()
}, [key, store])

const setValue = useCallback(
async (v: string | null) => {
setValueState(v)
if (v == null) {
return store.removeItem(key)
}
return store.setItem(key, v)
},
[key, store],
)

return [value, setValue]
}

export type GooglePickerViewProps = {
uppy: Uppy<any, any>
clientId: string
Expand Down

0 comments on commit 3d88f05

Please sign in to comment.