Today, we will install & setup vite + react + typescript + material ui (MUI 5). We will use react 18 and vite 3 and mui 5.
view

Install React Project With Vite

Install vite via npm:

npm create vite@latest
Enter fullscreen mode Exit fullscreen mode

Install vite via yarn:

yarn create vite
Enter fullscreen mode Exit fullscreen mode

Select react.

? Select a framework:  - Use arrow-keys. Return to submit.
  vanilla
  vue
 react
  preact
  lit
  svelte
Enter fullscreen mode Exit fullscreen mode

Select react js with typescript.

 Select a framework:  react
? Select a variant:  - Use arrow-keys. Return to submit.
  react
 react-ts
Enter fullscreen mode Exit fullscreen mode

Move to project directory and install dependencies.

cd react-mui
npm install 
npm run dev 
Enter fullscreen mode Exit fullscreen mode

Install React Material UI 5 (MUI)

install mui 5 via npm:

npm install @mui/material @emotion/react @emotion/styled
Enter fullscreen mode Exit fullscreen mode

Or install mui 5 via yarn:

yarn add @mui/material @emotion/react @emotion/styled
Enter fullscreen mode Exit fullscreen mode

import mui button component in App.tsx.
src/App.tsx

import { useState } from 'react';
import reactLogo from './assets/react.svg';
import './App.css';
import { Button } from '@mui/material';

function App() {
  const [count, setCount] = useState(0);

  return (
    <div className="App">
      <div>
        <a href="https://vitejs.dev" target="_blank">
          <img src="/vite.svg" className="logo" alt="Vite logo" />
        </a>
        <a href="https://reactjs.org" target="_blank">
          <img src={reactLogo} className="logo react" alt="React logo" />
        </a>
      </div>
      <h1>Vite + React + + Typescript + MUI 5</h1>
      <Button color="secondary">Secondary</Button>
      <Button variant="contained" color="success">
        Success
      </Button>
      <Button variant="outlined" color="error">
        Error
      </Button>
      <div className="card">
        <button onClick={() => setCount((count) => count + 1)}>
          count is {count}
        </button>
        <p>
          Edit <code>src/App.tsx</code> and save to test HMR
        </p>
      </div>
      <p className="read-the-docs">
        Click on the Vite and React logos to learn more
      </p>
    </div>
  );
}

export default App;
Enter fullscreen mode Exit fullscreen mode

install vite + react 18 + typescript + mui 5

Logo

React社区为您提供最前沿的新闻资讯和知识内容

更多推荐