Skip to content
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

example: upgrade React example to use React 18 #4002

Merged
merged 1 commit into from Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Expand Up @@ -200,6 +200,7 @@ module.exports = {
'examples/node-xhr/*.js',
'examples/php-xhr/*.js',
'examples/python-xhr/*.js',
'examples/react-example/*.js',
'examples/transloadit/*.js',
'examples/transloadit-markdown-bin/*.js',
'examples/xhr-bundle/*.js',
Expand Down
5 changes: 0 additions & 5 deletions examples/react-example/.babelrc.js

This file was deleted.

3 changes: 0 additions & 3 deletions examples/react-example/.gitignore

This file was deleted.

18 changes: 12 additions & 6 deletions examples/react-example/App.js → examples/react-example/App.jsx
@@ -1,11 +1,17 @@
/* eslint-disable */
const React = require('react')
const Uppy = require('@uppy/core')
const Tus = require('@uppy/tus')
const GoogleDrive = require('@uppy/google-drive')
const { Dashboard, DashboardModal, DragDrop, ProgressBar, FileInput } = require('@uppy/react')
import React from'react'
import Uppy from'@uppy/core'
import Tus from'@uppy/tus'
import GoogleDrive from'@uppy/google-drive'
import { Dashboard, DashboardModal, DragDrop, ProgressBar, FileInput } from'@uppy/react'

module.exports = class App extends React.Component {
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'

export default class App extends React.Component {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be best to rewrite this to hook to show useUppy. We frequently get issues about people forgetting useUppy and hooks is what people write these days.

constructor (props) {
super(props)

Expand Down
30 changes: 30 additions & 0 deletions examples/react-example/README.md
@@ -0,0 +1,30 @@
# React example

This is minimal example created to demonstrate how to integrate Uppy in your
React app.

To spawn the demo, use the following commands:

```sh
corepack yarn install
corepack yarn build
corepack yarn workspace @uppy-example/react dev
```

If you'd like to use a different package manager than Yarn (e.g. npm) to work
with this example, you can extract it from the workspace like this:

```sh
corepack yarn workspace @uppy-example/react pack

# The above command should have create a .tgz file, we're going to extract it to
# a new directory outside of the Uppy workspace.
mkdir ../react-example
tar -xzf examples/react-example/package.tgz -C ../react-example --strip-components 1
rm -f examples/react-example/package.tgz

# Now you can leave the Uppy workspace and use the example as a standalone JS project:
cd ../react-example
npm i
npm run dev
```
2 changes: 1 addition & 1 deletion examples/react-example/index.html
Expand Up @@ -8,6 +8,6 @@
</head>
<body>
<div id="app"></div>
<script src="bundle.js"></script>
<script src="./main.jsx" type="module"></script>
</body>
</html>
8 changes: 0 additions & 8 deletions examples/react-example/main.js

This file was deleted.

8 changes: 8 additions & 0 deletions examples/react-example/main.jsx
@@ -0,0 +1,8 @@
/* eslint-disable */
import React from 'react'
import { createRoot } from 'react-dom/client';
import App from './App.jsx'

createRoot(document.querySelector('#app')).render(
<App />
)
28 changes: 19 additions & 9 deletions examples/react-example/package.json
@@ -1,17 +1,27 @@
{
"name": "@uppy-example/react-example",
"name": "@uppy-example/react",
"version": "0.0.0",
"type": "module",
"dependencies": {
"@babel/core": "^7.4.5",
"@babel/preset-react": "^7.0.0",
"babelify": "^10.0.0",
"budo": "^11.6.2",
"react": "^16.8.6",
"react-dom": "^16.8.6"
"@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/tus": "workspace:*",
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"private": true,
"scripts": {
"css": "cp ../../packages/uppy/dist/uppy.min.css .",
"start": "yarn run css && budo main.js:bundle.js -- -r react:react -r react-dom:react-dom -t babelify"
"dev": "vite",
"build": "vite build",
"preview": "vite preview --port 5050"
},
"devDependencies": {
"@vitejs/plugin-react": "^2.0.0",
"vite": "^3.0.0"
}
}
7 changes: 7 additions & 0 deletions examples/react-example/vite.config.js
@@ -0,0 +1,7 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
})