这里需要引入 React 不然ts会报错

来源:7-7 【路由拓展】如何支持类组件

Darkholme

2022-06-14

老师这里不引入 React 了话会报’React’ refers to a UMD global, but the current file is a module. Consider adding an import instead. 为啥呢?

写回答

1回答

阿莱克斯刘

2022-06-29


如果不想引用react,那么你得先确保

  • typescript 至少是 version 4.1

  • react and react-dom 至少是 version 17

  • tsconfig.json 的 jsx compilerOption 需要改为 react-jsx or react-jsxdev

https://img.mukewang.com/szimg/62bbea25092dd90e05360322.jpg

参考:

https://stackoverflow.com/questions/64656055/react-refers-to-a-umd-global-but-the-current-file-is-a-module

0
0

React18 系统精讲 结合TS打造旅游电商平台

React18 精讲 + 结合 TS 实战 + 热门业务开发,获取必备技能

1993 学习 · 1015 问题

查看课程