Pārlūkot izejas kodu

move useStore out of core (#5533)

https://github.com/transloadit/uppy/pull/5443#discussion_r1862342884
(cherry picked from commit 00070c870f76876aca92e97f410f8b52085191bc)
Mikael Finstad 4 mēneši atpakaļ
vecāks
revīzija
0648fa7633

+ 0 - 28
packages/@uppy/core/src/useStore.ts

@@ -1,28 +0,0 @@
-import { useCallback, useEffect, useState } from 'preact/hooks'
-
-import type { AsyncStore } from './Uppy'
-
-export default 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]
-}

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

@@ -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 {
@@ -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