Skip to content

Commit

Permalink
examples: make React example up-to-date (#5205)
Browse files Browse the repository at this point in the history
  • Loading branch information
Murderlon authored May 30, 2024
1 parent 28767b4 commit c148139
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 132 deletions.
114 changes: 0 additions & 114 deletions examples/react-example/App.jsx

This file was deleted.

49 changes: 49 additions & 0 deletions examples/react-example/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* eslint-disable */
import React from 'react'
import Uppy from '@uppy/core'
import Tus from '@uppy/tus'
import Webcam from '@uppy/webcam'
import RemoteSources from '@uppy/remote-sources'
import { Dashboard, useUppyState } from '@uppy/react'

import '@uppy/core/dist/style.css'
import '@uppy/dashboard/dist/style.css'
import '@uppy/drag-drop/dist/style.css'
import '@uppy/file-input/dist/style.css'
import '@uppy/progress-bar/dist/style.css'

const metaFields = [
{ id: 'license', name: 'License', placeholder: 'specify license' },
]

function createUppy() {
return new Uppy({ restrictions: { requiredMetaFields: ['license'] } })
.use(Tus, { endpoint: 'https://tusd.tusdemo.net/files/' })
.use(Webcam)
.use(RemoteSources, {
companionUrl: 'https://companion.uppy.io',
})
}

export default function App() {
// IMPORTANT: passing an initaliser function to useState
// to prevent creating a new Uppy instance on every render.
// useMemo is a performance hint, not a guarantee.
const [uppy] = React.useState(createUppy)
// You can access state reactively with useUppyState
const fileCount = useUppyState(
uppy,
(state) => Object.keys(state.files).length,
)
const totalProgress = useUppyState(uppy, (state) => state.totalProgress)
// Also possible to get the state of all plugins.
const plugins = useUppyState(uppy, (state) => state.plugins)

return (
<>
<p>File count: {fileCount}</p>
<p>Total progress: {totalProgress}</p>
<Dashboard uppy={uppy} metaFields={metaFields} />
</>
)
}
2 changes: 1 addition & 1 deletion examples/react-example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
</head>
<body>
<div id="app"></div>
<script src="./main.jsx" type="module"></script>
<script src="./main.tsx" type="module"></script>
</body>
</html>
8 changes: 0 additions & 8 deletions examples/react-example/main.jsx

This file was deleted.

6 changes: 6 additions & 0 deletions examples/react-example/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-disable */
import React from 'react'
import { createRoot } from 'react-dom/client'
import App from './App.tsx'

createRoot(document.querySelector('#app')).render(<App />)
5 changes: 1 addition & 4 deletions examples/react-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
"dependencies": {
"@uppy/core": "workspace:*",
"@uppy/dashboard": "workspace:*",
"@uppy/drag-drop": "workspace:*",
"@uppy/file-input": "workspace:*",
"@uppy/google-drive": "workspace:*",
"@uppy/progress-bar": "workspace:*",
"@uppy/react": "workspace:*",
"@uppy/remote-sources": "workspace:*",
"@uppy/tus": "workspace:*",
"react": "^18.0.0",
"react-dom": "^18.0.0"
Expand Down
21 changes: 21 additions & 0 deletions examples/react-example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"jsxImportSource": "react",
"jsx": "react-jsx",
"esModuleInterop": true,
"skipLibCheck": true,
"target": "es2022",
"allowJs": true,
"resolveJsonModule": true,
"moduleDetection": "force",
"isolatedModules": true,
"verbatimModuleSyntax": true,
"strict": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,
"module": "NodeNext",
"outDir": "dist",
"sourceMap": true,
"lib": ["es2022", "dom", "dom.iterable"],
},
}
7 changes: 2 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8659,11 +8659,8 @@ __metadata:
dependencies:
"@uppy/core": "workspace:*"
"@uppy/dashboard": "workspace:*"
"@uppy/drag-drop": "workspace:*"
"@uppy/file-input": "workspace:*"
"@uppy/google-drive": "workspace:*"
"@uppy/progress-bar": "workspace:*"
"@uppy/react": "workspace:*"
"@uppy/remote-sources": "workspace:*"
"@uppy/tus": "workspace:*"
"@vitejs/plugin-react": "npm:^4.0.0"
react: "npm:^18.0.0"
Expand Down Expand Up @@ -9040,7 +9037,7 @@ __metadata:
languageName: unknown
linkType: soft

"@uppy/file-input@workspace:*, @uppy/file-input@workspace:^, @uppy/file-input@workspace:packages/@uppy/file-input":
"@uppy/file-input@workspace:^, @uppy/file-input@workspace:packages/@uppy/file-input":
version: 0.0.0-use.local
resolution: "@uppy/file-input@workspace:packages/@uppy/file-input"
dependencies:
Expand Down

0 comments on commit c148139

Please sign in to comment.