Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 719
umutfirat Avatar asked Feb 04 '26 19:02

umutfirat


1 Answers

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.

like image 57
zithir Avatar answered Feb 07 '26 10:02

zithir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!