App.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* eslint-disable */
  2. import React from 'react'
  3. import Uppy from '@uppy/core'
  4. import Tus from '@uppy/tus'
  5. import Webcam from '@uppy/webcam'
  6. import RemoteSources from '@uppy/remote-sources'
  7. import { Dashboard, useUppyState } from '@uppy/react'
  8. import '@uppy/core/dist/style.css'
  9. import '@uppy/dashboard/dist/style.css'
  10. import '@uppy/drag-drop/dist/style.css'
  11. import '@uppy/file-input/dist/style.css'
  12. import '@uppy/progress-bar/dist/style.css'
  13. const metaFields = [
  14. { id: 'license', name: 'License', placeholder: 'specify license' },
  15. ]
  16. function createUppy() {
  17. return new Uppy({ restrictions: { requiredMetaFields: ['license'] } })
  18. .use(Tus, { endpoint: 'https://tusd.tusdemo.net/files/' })
  19. .use(Webcam)
  20. .use(RemoteSources, {
  21. companionUrl: 'https://companion.uppy.io',
  22. })
  23. }
  24. export default function App() {
  25. // IMPORTANT: passing an initaliser function to useState
  26. // to prevent creating a new Uppy instance on every render.
  27. // useMemo is a performance hint, not a guarantee.
  28. const [uppy] = React.useState(createUppy)
  29. // You can access state reactively with useUppyState
  30. const fileCount = useUppyState(
  31. uppy,
  32. (state) => Object.keys(state.files).length,
  33. )
  34. const totalProgress = useUppyState(uppy, (state) => state.totalProgress)
  35. // Also possible to get the state of all plugins.
  36. const plugins = useUppyState(uppy, (state) => state.plugins)
  37. return (
  38. <>
  39. <p>File count: {fileCount}</p>
  40. <p>Total progress: {totalProgress}</p>
  41. <Dashboard uppy={uppy} metaFields={metaFields} />
  42. </>
  43. )
  44. }