React + Vite + TS
De Banane Atomic
Aller à la navigationAller à la recherche
Links
Command line
# create a new project (framework: React, variant: TypeScript) npm create vite@latest # install the packages npm install # run the project npm run dev |
Basic App
public/index.html |
<body> <!-- hosts the React application --> <div id="root"></div> <!-- import index.js generated from index.jsx by a bundler such as Snowpack --> <script type="module" src="/src/main.tsx"></script> </body> |
src/main.tsx |
import { StrictMode } from 'react' import { createRoot } from 'react-dom/client' createRoot(document.getElementById('root')!).render( <StrictMode> <h1>My App</h1> </StrictMode>, ) |
package.json |
{ "name": "vite-project", "private": true, "version": "0.0.0", "type": "module", "scripts": { "dev": "vite", "build": "tsc -b && vite build", "lint": "eslint .", "preview": "vite preview" }, "dependencies": { "react": "^18.3.1", "react-dom": "^18.3.1" }, "devDependencies": { "@eslint/js": "^9.13.0", "@types/react": "^18.3.11", "@types/react-dom": "^18.3.1", "@vitejs/plugin-react": "^4.3.3", "eslint": "^9.13.0", "eslint-plugin-react-hooks": "^5.0.0", "eslint-plugin-react-refresh": "^0.4.13", "globals": "^15.11.0", "typescript": "~5.6.2", "typescript-eslint": "^8.10.0", "vite": "^5.4.9" } } |
Component
src/App.jsx |
import React from 'react'; function App() { return ( // one root element <article> <h1>Recipe Manager</h1> </article> ) } export default App; |
src/index.jsx |
import React from 'react'; import ReactDOM from 'react-dom'; import App from './App'; ReactDOM.render( <App />, document.getElementById('app') ); |