From 29d78940c2a90463d73c7b6ab3215dde47d9c7a1 Mon Sep 17 00:00:00 2001 From: Miguel Angel Chimali Cobano Date: Fri, 5 Sep 2025 08:02:12 +0200 Subject: [PATCH 1/4] refactor: react hooks migration to vite and react 19 --- .../06-ajax-field-change/.babelrc | 7 - .../06-ajax-field-change/Readme.md | 4 +- .../06-ajax-field-change/Readme_es.md | 2 +- .../src => 06-ajax-field-change}/index.html | 9 +- .../06-ajax-field-change/package.json | 48 +-- .../06-ajax-field-change/tsconfig.json | 25 +- .../06-ajax-field-change/vite.config.ts | 7 + .../06-ajax-field-change/webpack.config.js | 54 ---- .../03-react-hooks/07-custom-hook/.babelrc | 7 - .../03-react-hooks/07-custom-hook/Readme.md | 12 +- .../src => 07-custom-hook}/index.html | 9 +- .../07-custom-hook/package.json | 48 +-- .../03-react-hooks/07-custom-hook/src/app.tsx | 2 +- .../07-custom-hook/tsconfig.json | 25 +- .../07-custom-hook/vite.config.ts | 7 + .../07-custom-hook/webpack.config.js | 54 ---- .../03-react-hooks/08-pure-component/.babelrc | 7 - .../08-pure-component/Readme_es.md | 2 +- .../08-pure-component/{src => }/index.html | 9 +- .../08-pure-component/package.json | 47 +-- .../08-pure-component/tsconfig.json | 25 +- .../08-pure-component/vite.config.ts | 7 + .../08-pure-component/webpack.config.js | 54 ---- .../09-pure-component-callback/.babelrc | 7 - .../{src => }/index.html | 9 +- .../09-pure-component-callback/package.json | 47 +-- .../09-pure-component-callback/tsconfig.json | 25 +- .../09-pure-component-callback/vite.config.ts | 7 + .../webpack.config.js | 54 ---- .../03-react-hooks/10-use-reducer/.babelrc | 7 - .../03-react-hooks/10-use-reducer/Readme.md | 2 +- .../03-react-hooks/10-use-reducer/index.html | 13 + .../10-use-reducer/package.json | 47 +-- .../10-use-reducer/src/index.html | 12 - .../10-use-reducer/tsconfig.json | 25 +- .../10-use-reducer/vite.config.ts | 7 + .../10-use-reducer/webpack.config.js | 54 ---- .../03-react-hooks/11-use-context/.babelrc | 7 - .../03-react-hooks/11-use-context/Readme.md | 40 ++- .../11-use-context/Readme_es.md | 33 ++- .../03-react-hooks/11-use-context/index.html | 13 + .../11-use-context/package.json | 47 +-- .../11-use-context/src/demo.tsx | 4 +- .../11-use-context/src/index.html | 12 - .../11-use-context/tsconfig.json | 25 +- .../11-use-context/vite.config.ts | 7 + .../11-use-context/webpack.config.js | 54 ---- .../03-react-hooks/12-set-state-func/.babelrc | 7 - .../12-set-state-func/Readme.md | 2 +- .../12-set-state-func/index.html | 13 + .../12-set-state-func/package.json | 47 +-- .../12-set-state-func/src/index.html | 12 - .../12-set-state-func/tsconfig.json | 25 +- .../12-set-state-func/vite.config.ts | 7 + .../12-set-state-func/webpack.config.js | 54 ---- .../03-react-hooks/13-async-closure/.babelrc | 7 - .../13-async-closure/index.html | 13 + .../13-async-closure/package.json | 47 +-- .../13-async-closure/src/index.html | 12 - .../13-async-closure/tsconfig.json | 25 +- .../13-async-closure/vite.config.ts | 7 + .../13-async-closure/webpack.config.js | 54 ---- .../03-react-hooks/14-use-ref-dom/.babelrc | 7 - .../14-use-ref-dom/Readme_es.md | 2 +- .../03-react-hooks/14-use-ref-dom/index.html | 13 + .../14-use-ref-dom/package.json | 47 +-- .../14-use-ref-dom/src/index.html | 12 - .../14-use-ref-dom/tsconfig.json | 25 +- .../14-use-ref-dom/vite.config.ts | 7 + .../14-use-ref-dom/webpack.config.js | 54 ---- .../03-react-hooks/15-memo-predicate/.babelrc | 7 - .../15-memo-predicate/Readme.md | 13 - .../15-memo-predicate/index.html | 13 + .../15-memo-predicate/package.json | 47 +-- .../15-memo-predicate/src/index.html | 12 - .../15-memo-predicate/src/index.tsx | 1 + .../15-memo-predicate/tsconfig.json | 25 +- .../15-memo-predicate/vite.config.ts | 7 + .../15-memo-predicate/webpack.config.js | 54 ---- .../16-use-debug-value/.babelrc | 7 - .../16-use-debug-value/index.html | 13 + .../16-use-debug-value/package.json | 47 +-- .../16-use-debug-value/src/index.html | 12 - .../16-use-debug-value/src/index.tsx | 1 + .../16-use-debug-value/tsconfig.json | 25 +- .../16-use-debug-value/vite.config.ts | 7 + .../16-use-debug-value/webpack.config.js | 54 ---- .../17-why-did-you-update/.babelrc | 7 - .../17-why-did-you-update/index.html | 13 + .../17-why-did-you-update/package.json | 47 +-- .../17-why-did-you-update/src/demo.tsx | 2 +- .../17-why-did-you-update/src/index.html | 12 - .../17-why-did-you-update/tsconfig.json | 25 +- .../17-why-did-you-update/vite.config.ts | 7 + .../17-why-did-you-update/webpack.config.js | 54 ---- .../03-react-hooks/18-use-promise/Readme.md | 123 ++++++++ .../18-use-promise/Readme_es.md | 278 ++++++++++++++++++ .../03-react-hooks/18-use-promise/index.html | 13 + .../18-use-promise/package.json | 24 ++ .../03-react-hooks/18-use-promise/src/app.tsx | 6 + .../18-use-promise/src/demo.tsx | 20 ++ .../18-use-promise/src/index.tsx | 8 + .../18-use-promise/src/parent.tsx | 34 +++ .../18-use-promise/src/styles.css | 3 + .../18-use-promise/tsconfig.json | 19 ++ .../18-use-promise/vite.config.ts | 7 + .../99-promise-unmounted-R17/.babelrc | 7 - .../99-promise-unmounted-R17/Readme.md | 4 +- .../99-promise-unmounted-R17/Readme_es.md | 4 +- .../99-promise-unmounted-R17/index.html | 13 + .../99-promise-unmounted-R17/package.json | 47 +-- .../99-promise-unmounted-R17/src/index.html | 12 - .../99-promise-unmounted-R17/tsconfig.json | 25 +- .../99-promise-unmounted-R17/vite.config.ts | 7 + .../webpack.config.js | 54 ---- 115 files changed, 1212 insertions(+), 1536 deletions(-) delete mode 100644 04-frameworks/01-react/03-react-hooks/06-ajax-field-change/.babelrc rename 04-frameworks/01-react/03-react-hooks/{07-custom-hook/src => 06-ajax-field-change}/index.html (54%) create mode 100644 04-frameworks/01-react/03-react-hooks/06-ajax-field-change/vite.config.ts delete mode 100644 04-frameworks/01-react/03-react-hooks/06-ajax-field-change/webpack.config.js delete mode 100644 04-frameworks/01-react/03-react-hooks/07-custom-hook/.babelrc rename 04-frameworks/01-react/03-react-hooks/{06-ajax-field-change/src => 07-custom-hook}/index.html (54%) create mode 100644 04-frameworks/01-react/03-react-hooks/07-custom-hook/vite.config.ts delete mode 100644 04-frameworks/01-react/03-react-hooks/07-custom-hook/webpack.config.js delete mode 100644 04-frameworks/01-react/03-react-hooks/08-pure-component/.babelrc rename 04-frameworks/01-react/03-react-hooks/08-pure-component/{src => }/index.html (54%) create mode 100644 04-frameworks/01-react/03-react-hooks/08-pure-component/vite.config.ts delete mode 100644 04-frameworks/01-react/03-react-hooks/08-pure-component/webpack.config.js delete mode 100644 04-frameworks/01-react/03-react-hooks/09-pure-component-callback/.babelrc rename 04-frameworks/01-react/03-react-hooks/09-pure-component-callback/{src => }/index.html (54%) create mode 100644 04-frameworks/01-react/03-react-hooks/09-pure-component-callback/vite.config.ts delete mode 100644 04-frameworks/01-react/03-react-hooks/09-pure-component-callback/webpack.config.js delete mode 100644 04-frameworks/01-react/03-react-hooks/10-use-reducer/.babelrc create mode 100644 04-frameworks/01-react/03-react-hooks/10-use-reducer/index.html delete mode 100644 04-frameworks/01-react/03-react-hooks/10-use-reducer/src/index.html create mode 100644 04-frameworks/01-react/03-react-hooks/10-use-reducer/vite.config.ts delete mode 100644 04-frameworks/01-react/03-react-hooks/10-use-reducer/webpack.config.js delete mode 100644 04-frameworks/01-react/03-react-hooks/11-use-context/.babelrc create mode 100644 04-frameworks/01-react/03-react-hooks/11-use-context/index.html delete mode 100644 04-frameworks/01-react/03-react-hooks/11-use-context/src/index.html create mode 100644 04-frameworks/01-react/03-react-hooks/11-use-context/vite.config.ts delete mode 100644 04-frameworks/01-react/03-react-hooks/11-use-context/webpack.config.js delete mode 100644 04-frameworks/01-react/03-react-hooks/12-set-state-func/.babelrc create mode 100644 04-frameworks/01-react/03-react-hooks/12-set-state-func/index.html delete mode 100644 04-frameworks/01-react/03-react-hooks/12-set-state-func/src/index.html create mode 100644 04-frameworks/01-react/03-react-hooks/12-set-state-func/vite.config.ts delete mode 100644 04-frameworks/01-react/03-react-hooks/12-set-state-func/webpack.config.js delete mode 100644 04-frameworks/01-react/03-react-hooks/13-async-closure/.babelrc create mode 100644 04-frameworks/01-react/03-react-hooks/13-async-closure/index.html delete mode 100644 04-frameworks/01-react/03-react-hooks/13-async-closure/src/index.html create mode 100644 04-frameworks/01-react/03-react-hooks/13-async-closure/vite.config.ts delete mode 100644 04-frameworks/01-react/03-react-hooks/13-async-closure/webpack.config.js delete mode 100644 04-frameworks/01-react/03-react-hooks/14-use-ref-dom/.babelrc create mode 100644 04-frameworks/01-react/03-react-hooks/14-use-ref-dom/index.html delete mode 100644 04-frameworks/01-react/03-react-hooks/14-use-ref-dom/src/index.html create mode 100644 04-frameworks/01-react/03-react-hooks/14-use-ref-dom/vite.config.ts delete mode 100644 04-frameworks/01-react/03-react-hooks/14-use-ref-dom/webpack.config.js delete mode 100644 04-frameworks/01-react/03-react-hooks/15-memo-predicate/.babelrc create mode 100644 04-frameworks/01-react/03-react-hooks/15-memo-predicate/index.html delete mode 100644 04-frameworks/01-react/03-react-hooks/15-memo-predicate/src/index.html create mode 100644 04-frameworks/01-react/03-react-hooks/15-memo-predicate/vite.config.ts delete mode 100644 04-frameworks/01-react/03-react-hooks/15-memo-predicate/webpack.config.js delete mode 100644 04-frameworks/01-react/03-react-hooks/16-use-debug-value/.babelrc create mode 100644 04-frameworks/01-react/03-react-hooks/16-use-debug-value/index.html delete mode 100644 04-frameworks/01-react/03-react-hooks/16-use-debug-value/src/index.html create mode 100644 04-frameworks/01-react/03-react-hooks/16-use-debug-value/vite.config.ts delete mode 100644 04-frameworks/01-react/03-react-hooks/16-use-debug-value/webpack.config.js delete mode 100644 04-frameworks/01-react/03-react-hooks/17-why-did-you-update/.babelrc create mode 100644 04-frameworks/01-react/03-react-hooks/17-why-did-you-update/index.html delete mode 100644 04-frameworks/01-react/03-react-hooks/17-why-did-you-update/src/index.html create mode 100644 04-frameworks/01-react/03-react-hooks/17-why-did-you-update/vite.config.ts delete mode 100644 04-frameworks/01-react/03-react-hooks/17-why-did-you-update/webpack.config.js create mode 100644 04-frameworks/01-react/03-react-hooks/18-use-promise/Readme.md create mode 100644 04-frameworks/01-react/03-react-hooks/18-use-promise/Readme_es.md create mode 100644 04-frameworks/01-react/03-react-hooks/18-use-promise/index.html create mode 100644 04-frameworks/01-react/03-react-hooks/18-use-promise/package.json create mode 100644 04-frameworks/01-react/03-react-hooks/18-use-promise/src/app.tsx create mode 100644 04-frameworks/01-react/03-react-hooks/18-use-promise/src/demo.tsx create mode 100644 04-frameworks/01-react/03-react-hooks/18-use-promise/src/index.tsx create mode 100644 04-frameworks/01-react/03-react-hooks/18-use-promise/src/parent.tsx create mode 100644 04-frameworks/01-react/03-react-hooks/18-use-promise/src/styles.css create mode 100644 04-frameworks/01-react/03-react-hooks/18-use-promise/tsconfig.json create mode 100644 04-frameworks/01-react/03-react-hooks/18-use-promise/vite.config.ts delete mode 100644 04-frameworks/01-react/03-react-hooks/99-promise-unmounted-R17/.babelrc create mode 100644 04-frameworks/01-react/03-react-hooks/99-promise-unmounted-R17/index.html delete mode 100644 04-frameworks/01-react/03-react-hooks/99-promise-unmounted-R17/src/index.html create mode 100644 04-frameworks/01-react/03-react-hooks/99-promise-unmounted-R17/vite.config.ts delete mode 100644 04-frameworks/01-react/03-react-hooks/99-promise-unmounted-R17/webpack.config.js diff --git a/04-frameworks/01-react/03-react-hooks/06-ajax-field-change/.babelrc b/04-frameworks/01-react/03-react-hooks/06-ajax-field-change/.babelrc deleted file mode 100644 index 469d3d55f..000000000 --- a/04-frameworks/01-react/03-react-hooks/06-ajax-field-change/.babelrc +++ /dev/null @@ -1,7 +0,0 @@ -{ - "presets": [ - "@babel/preset-env", - "@babel/preset-typescript", - "@babel/preset-react" - ] -} diff --git a/04-frameworks/01-react/03-react-hooks/06-ajax-field-change/Readme.md b/04-frameworks/01-react/03-react-hooks/06-ajax-field-change/Readme.md index b7789b8e5..27078f513 100644 --- a/04-frameworks/01-react/03-react-hooks/06-ajax-field-change/Readme.md +++ b/04-frameworks/01-react/03-react-hooks/06-ajax-field-change/Readme.md @@ -1,6 +1,6 @@ # 06 Ajax field change -## Resume +## Summary This example takes as a starting point the example \ \_05-component-update-render. @@ -16,7 +16,7 @@ As a bonus, we will check how to use Debounce (wait a little until the user stop npm install ``` -- Let's open the _demo.js_, and let's add an entry in the state that stores the current search filter, and another state in which we +- Let's open the _demo.tsx_, and let's add an entry in the state that stores the current search filter, and another state in which we are going to store a list of users. _./src/demo.tsx_ diff --git a/04-frameworks/01-react/03-react-hooks/06-ajax-field-change/Readme_es.md b/04-frameworks/01-react/03-react-hooks/06-ajax-field-change/Readme_es.md index 6e0d253f3..4fecef354 100644 --- a/04-frameworks/01-react/03-react-hooks/06-ajax-field-change/Readme_es.md +++ b/04-frameworks/01-react/03-react-hooks/06-ajax-field-change/Readme_es.md @@ -21,7 +21,7 @@ así llamadas innecesarias). npm install ``` -- Vamos abrir el fichero _demo.js_ y vamos añadir una entrada en el +- Vamos abrir el fichero _demo.tsx_ y vamos añadir una entrada en el estado que almacene el filtro actual de busqueda, y otra en la que almacene una lista de usuarios. diff --git a/04-frameworks/01-react/03-react-hooks/07-custom-hook/src/index.html b/04-frameworks/01-react/03-react-hooks/06-ajax-field-change/index.html similarity index 54% rename from 04-frameworks/01-react/03-react-hooks/07-custom-hook/src/index.html rename to 04-frameworks/01-react/03-react-hooks/06-ajax-field-change/index.html index a3d74b719..fe100be04 100644 --- a/04-frameworks/01-react/03-react-hooks/07-custom-hook/src/index.html +++ b/04-frameworks/01-react/03-react-hooks/06-ajax-field-change/index.html @@ -1,12 +1,13 @@ - - - - My App Example + + + React App - React hooks +
+ diff --git a/04-frameworks/01-react/03-react-hooks/06-ajax-field-change/package.json b/04-frameworks/01-react/03-react-hooks/06-ajax-field-change/package.json index d434b896c..cb10a2306 100644 --- a/04-frameworks/01-react/03-react-hooks/06-ajax-field-change/package.json +++ b/04-frameworks/01-react/03-react-hooks/06-ajax-field-change/package.json @@ -1,40 +1,24 @@ { - "name": "react-example", - "version": "1.0.0", - "description": "", - "main": "index.js", + "name": "hello-vite", + "private": true, + "version": "0.0.0", + "type": "module", "scripts": { - "start": "run-p -l type-check:watch start:dev", - "type-check": "tsc --noEmit", - "type-check:watch": "npm run type-check -- --watch", - "start:dev": "webpack-dev-server --mode development --open", - "build": "rimraf dist && webpack --mode development" + "start": "vite --host", + "build": "vite build", + "preview": "vite preview" }, - "author": "", - "license": "ISC", "devDependencies": { - "@babel/cli": "^7.17.10", - "@babel/core": "^7.17.10", - "@babel/preset-env": "^7.17.10", - "@babel/preset-react": "^7.17.12", - "@babel/preset-typescript": "^7.16.7", - "@types/react": "^18.0.9", - "@types/react-dom": "^18.0.4", - "babel-loader": "^8.2.5", - "css-loader": "^6.7.1", - "html-loader": "^3.1.0", - "html-webpack-plugin": "^5.5.0", - "npm-run-all": "^4.1.5", - "rimraf": "^3.0.2", - "style-loader": "^3.3.1", - "typescript": "^4.6.4", - "webpack": "^5.72.1", - "webpack-cli": "^4.9.2", - "webpack-dev-server": "^4.9.0" + "@types/react": "^19.1.8", + "@types/react-dom": "^19.1.6", + "@vitejs/plugin-react": "^4.6.0", + "typescript": "^5.8.3", + "vite": "^7.0.4", + "vite-plugin-checker": "^0.10.0" }, "dependencies": { - "react": "^18.1.0", - "react-dom": "^18.1.0", - "use-debounce": "^8.0.1" + "react": "^19.1.0", + "react-dom": "^19.1.0", + "use-debounce": "^10.0.5" } } diff --git a/04-frameworks/01-react/03-react-hooks/06-ajax-field-change/tsconfig.json b/04-frameworks/01-react/03-react-hooks/06-ajax-field-change/tsconfig.json index 3312b5f1e..a057cea1d 100644 --- a/04-frameworks/01-react/03-react-hooks/06-ajax-field-change/tsconfig.json +++ b/04-frameworks/01-react/03-react-hooks/06-ajax-field-change/tsconfig.json @@ -1,18 +1,19 @@ { "compilerOptions": { - "target": "es6", - "module": "es6", - "moduleResolution": "node", - "declaration": false, + "esModuleInterop": true, + "isolatedModules": true, + "jsx": "react-jsx", + "lib": ["ESNext", "DOM"], + "module": "ESNext", + "moduleResolution": "bundler", + "noEmit": true, "noImplicitAny": false, - "allowSyntheticDefaultImports": true, - "sourceMap": true, - "jsx": "react", - "noLib": false, - "suppressImplicitAnyIndexErrors": true, + "noImplicitReturns": true, + "resolveJsonModule": true, "skipLibCheck": true, - "esModuleInterop": true + "sourceMap": true, + "target": "ESNext", + "useDefineForClassFields": true }, - "include": ["src/**/*"], - "exclude": ["node_modules"] + "include": ["src"] } diff --git a/04-frameworks/01-react/03-react-hooks/06-ajax-field-change/vite.config.ts b/04-frameworks/01-react/03-react-hooks/06-ajax-field-change/vite.config.ts new file mode 100644 index 000000000..a0024d88e --- /dev/null +++ b/04-frameworks/01-react/03-react-hooks/06-ajax-field-change/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from "vite"; +import checker from "vite-plugin-checker"; +import react from "@vitejs/plugin-react"; + +export default defineConfig({ + plugins: [checker({ typescript: true }), react()], +}); diff --git a/04-frameworks/01-react/03-react-hooks/06-ajax-field-change/webpack.config.js b/04-frameworks/01-react/03-react-hooks/06-ajax-field-change/webpack.config.js deleted file mode 100644 index 326060f82..000000000 --- a/04-frameworks/01-react/03-react-hooks/06-ajax-field-change/webpack.config.js +++ /dev/null @@ -1,54 +0,0 @@ -const HtmlWebpackPlugin = require("html-webpack-plugin"); -const path = require("path"); -const basePath = __dirname; - -module.exports = { - context: path.join(basePath, "src"), - resolve: { - extensions: [".js", ".ts", ".tsx"], - }, - entry: { - app: ["./index.tsx", "./styles.css"], - }, - devtool: "eval-source-map", - stats: "errors-only", - output: { - filename: "[name].[chunkhash].js", - }, - module: { - rules: [ - { - test: /\.tsx?$/, - exclude: /node_modules/, - loader: "babel-loader", - }, - { - test: /\.(png|jpg)$/, - type: "asset/resource", - }, - { - test: /\.html$/, - loader: "html-loader", - }, - { - test: /\.css$/, - exclude: /node_modules/, - use: [ - { - loader: "style-loader", - }, - { - loader: "css-loader", - }, - ], - }, - ], - }, - plugins: [ - //Generate index.html in /dist => https://github.com/ampedandwired/html-webpack-plugin - new HtmlWebpackPlugin({ - filename: "index.html", //Name of file in ./dist/ - template: "index.html", //Name of template in ./src - }), - ], -}; diff --git a/04-frameworks/01-react/03-react-hooks/07-custom-hook/.babelrc b/04-frameworks/01-react/03-react-hooks/07-custom-hook/.babelrc deleted file mode 100644 index 469d3d55f..000000000 --- a/04-frameworks/01-react/03-react-hooks/07-custom-hook/.babelrc +++ /dev/null @@ -1,7 +0,0 @@ -{ - "presets": [ - "@babel/preset-env", - "@babel/preset-typescript", - "@babel/preset-react" - ] -} diff --git a/04-frameworks/01-react/03-react-hooks/07-custom-hook/Readme.md b/04-frameworks/01-react/03-react-hooks/07-custom-hook/Readme.md index b7cc0439c..ac3763b4f 100644 --- a/04-frameworks/01-react/03-react-hooks/07-custom-hook/Readme.md +++ b/04-frameworks/01-react/03-react-hooks/07-custom-hook/Readme.md @@ -1,8 +1,8 @@ # 07 Custom hooks -## Resume +## Summary -This example takes as its starting point the \ _06-ajax-field-change example. +This example takes as its starting point the \ \_06-ajax-field-change example. Hooks are cool, but our functional component seems to get cluttered, is there a way to extract functionality outside the functional component? @@ -31,13 +31,13 @@ export const MyComponent = () => { // Load full list when the component gets mounted and filter gets updated React.useEffect(() => { fetch(`https://jsonplaceholder.typicode.com/users?name_like=${filter}`) - .then(response => response.json()) - .then(json => setUserCollection(json)); + .then((response) => response.json()) + .then((json) => setUserCollection(json)); }, [filter]); return (
- setFilter(e.target.value)} /> + setFilter(e.target.value)} />