uppy/packages/@uppy/react/src/useRemoteSource.ts
Prakash 1427add64a
@uppy/upgrade-devdeps-v1 (#6317)
Part of the dev-dependency major-version upgrades. These required code
changes so they're split out from the no-code-change batch (#6315).

**AI Disclaimer** : AI Used

- **glob 8 → 13** — `@uppy/locales` scripts: the callback API was
removed, so `getPaths()` uses the promise form and `test.mjs` uses the
named `globSync`.
- **npm-packlist 5 → 11** — `upload-to-cdn.js`: v7+ takes an
`@npmcli/arborist` tree instead of `{ path }`; loads the tree and passes
it to `packlist()`. Adds `@npmcli/arborist` as a devDependency.
- **nock 13 → 14** (`@uppy/companion`) — the v14 @mswjs/interceptors
rewrite crashed the SSRF tests in `http-agent.test.ts`; nock
interception is now kept off by default and only activated for the one
test that mocks a host.
- **@types/use-sync-external-store 0 → 1** — `@uppy/react`: v1's exports
map only exposes extensionless subpaths, so imports use
`use-sync-external-store/shim` and `/with-selector` (runtime supports
both).
2026-06-03 14:38:14 +05:30

34 lines
796 B
TypeScript

import {
createRemoteSourceController,
type RemoteSourceKeys,
type RemoteSourceSnapshot,
} from '@uppy/components'
import { useEffect, useMemo } from 'react'
import { useSyncExternalStore } from 'use-sync-external-store/shim'
import { useUppyContext } from './headless/UppyContextProvider.js'
export function useRemoteSource(
sourceId: RemoteSourceKeys,
): RemoteSourceSnapshot {
const { uppy } = useUppyContext()
const controller = useMemo(
() => createRemoteSourceController(uppy, sourceId),
[uppy, sourceId],
)
const store = useSyncExternalStore(
controller.subscribe,
controller.getSnapshot,
controller.getSnapshot,
)
useEffect(() => {
controller.mount()
return () => {
controller.unmount()
}
}, [controller])
return store
}