Skip to content

Commit 0648fa7

Browse files
authored
move useStore out of core (#5533)
#5443 (comment) (cherry picked from commit 00070c870f76876aca92e97f410f8b52085191bc)
1 parent afd4bef commit 0648fa7

File tree

2 files changed

+25
-29
lines changed

2 files changed

+25
-29
lines changed

packages/@uppy/core/src/useStore.ts

-28
This file was deleted.

packages/@uppy/provider-views/src/GooglePicker/GooglePickerView.tsx

+25-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { h } from 'preact'
22
import { useCallback, useEffect, useRef, useState } from 'preact/hooks'
33

44
import type { Uppy } from '@uppy/core'
5-
import useStore from '@uppy/core/lib/useStore.js'
65
import type { AsyncStore } from '@uppy/core/lib/Uppy.js'
76

87
import {
@@ -19,6 +18,31 @@ import {
1918
import AuthView from '../ProviderView/AuthView.js'
2019
import { GoogleDriveIcon, GooglePhotosIcon } from './icons.js'
2120

21+
function useStore(
22+
store: AsyncStore,
23+
key: string,
24+
): [string | undefined | null, (v: string | null) => Promise<void>] {
25+
const [value, setValueState] = useState<string | null | undefined>()
26+
useEffect(() => {
27+
;(async () => {
28+
setValueState(await store.getItem(key))
29+
})()
30+
}, [key, store])
31+
32+
const setValue = useCallback(
33+
async (v: string | null) => {
34+
setValueState(v)
35+
if (v == null) {
36+
return store.removeItem(key)
37+
}
38+
return store.setItem(key, v)
39+
},
40+
[key, store],
41+
)
42+
43+
return [value, setValue]
44+
}
45+
2246
export type GooglePickerViewProps = {
2347
uppy: Uppy<any, any>
2448
clientId: string

0 commit comments

Comments
 (0)