Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

How to use React in Typescript

$
0
0

Hi,

I try to build my first React project. I created an asp.core project and using npm I installed react typescript and typings of react and react.dom.

I created under my project root folder a folder called "Scripts" and subfolders "src" and "dist".

My package.json is:

{
"name": "package.json",
"version": "1.0.0",
"description": "ReactProject",
"main": "index.js",
"scripts": {
"test": "hello"
},
"author": "",
"license": "ISC",
"dependencies": {
"@types/react": "^15.0.14",
"@types/react-dom": "^0.14.23",
"react": "^15.4.2",
"react-dom": "^15.4.2"
},
"devDependencies": {
"source-map-loader": "^0.1.6",
"ts-loader": "^2.0.1"
}
}

and my tsconfig.json is 

{
"compilerOptions": {
"outDir": "./Scripts/",
"sourceMap": true,
"noImplicitAny": true,
"module": "commonjs",
"target": "es5",
"jsx": "react"
},
"exclude": [
"node_modules",
"wwwroot"
]
}

However, when I add a *.tsx file under "Scripts/src" folder and write "import*asReactfrom"react", VS show me the error "cannot find modle react".

Why VS did not reconize react module?


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>