-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
examples: make React example up-to-date #5205
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} /> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 />) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this could be simplified as
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit of an anti-pattern in the selector/lenses pattern. Selector should have a single purpose and the selector determines how often the hook needs to re-render based on the subset of state it returns, which is very big and deep in your case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we should add a comment about that