I am attempting to write a cordova app with ts and react by starting with the boilerplate: https://github.com/davidgerrard/cordova-react-typescript-webpack-boilerplate
The cloned code works fine, but when I attempt to write my own component I start with a typical:
import React, { useState } from 'react';
It imports React just fine, but tells me
Module '"react"' has no exported member 'useState'
I am used to react on the web, so is there some different way to do this for cordova? Or is there something that may need to be configured and/or updated?
For me, there was a mismatch between my react version (17.0.2) and my @types/react version (17.0.37). Installing the same version of types solved my issue.
npm i --save-dev @types/[email protected]
TL;DR? User zero298 nailed it.
If you ever get this error it is because you are using an old pre-hooks version of React.
The easiest fix is to simply run "npm upgrade" (or yarn, or whatever your preferred package manager is)
I hope others googling this error can learn from my mistakes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With