error: Property ‘setState‘ does not exist on type ‘Home‘
On Error not type does Property exist home
2023-09-27 14:28:54 时间
问题描述:
我在react中用typescript时,定义一个Home组件,然后在组件里用setState时会有这样一个报错:(如图)Property 'setState' does not exist on type 'Home'
分析解决:
报错说我的Home组件上不存在setState属性,但是我把文件的后缀名从‘.tsx’改成‘.jsx’就不报这个错了,推断是typescript的类型检查报的这个错,识别不了react组件就不认为这个class函数上有setState属性。安装一下react、react-dom的类型定义就解决啦
npm install --save-dev "@types/react" "@types/react-dom"
相关文章
- Golang filepath.Walk panic error on large directory
- [GeoDjango] 00 - Install PostgreSQL on Ubuntu
- UVa 825 Walking on the Safe Side(DP)
- ASP.NET Core – Handle Error on Razor Page
- ****Call to a member function item() on a non-object
- MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error
- tensorflow build failed on Centos with Error: suffix or operands invalid for ""
- Using pg_dump restore dump file on Odoo
- Error: Another program is already listening on a port that one of our HTTP servers is configured to use. Shut this program down first before starting
- 解决xxx by CORS policy: No ‘Access-Control-Allow-Origin‘ header is present on the requested resource问题
- UVALive 4818 - Largest Empty Circle on a Segment (计算几何)
- 解决Error: unable to perform an operation on node ‘rabbit@DESKTOP-xxx‘. Please see diagnostics informa
- 在Ubuntu12.10下安装Ruby On Rails
- php-fpm开启报错-ERROR: An another FPM instance seems to already listen on /tmp/php-cgi.sock
- C. On Number of Decompositions into Multipliers -- Codeforces
- UserMailbox 必须强制使用 Database---Database is mandatory on UserMailbox error
- Speeding up Migration on ApsaraDB for Redis
- Hive On Spark和SparkSQL