umutfirat
umutfirat

Reputation: 183

Vite Typescript for React 17

Is there any way to install Vite and Typescript for React 17 instead of 18? We are using React 17.0.2 at work and considering to move Typescript.

Upvotes: 13

Views: 6318

Answers (1)

zithir
zithir

Reputation: 895

I was not able to find a command to do so using vite cli, but you can switch to react 17 manually without trouble. After creating a Vite react project, inside you have to first install older react version:

npm i react@17 react-dom@17

And also when using typescript:

npm i -D @types/react@17 @types/react-dom@17

Then since React 18 uses new method to render into document, you also need to change main.jsx or main.tsx to use old render method:

...
import ReactDOM from "react-dom"
...

ReactDOM.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
  document.getElementById("root")
);

Then you should be good to go.

Upvotes: 24

Related Questions