在以下代码中,我收到TypeScript错误:
This expression is not callable. Type 'typeof React' has no call signatures TS2349
我需要以什么方式声明类型?感谢我在React中习惯TypeScript的帮助。
useEffect(() => {
// subscribe to some data source
console.log('subscribe to some data source');
return () => {
// unsubscribe to avoid memory leak
console.log('this will run when the component unmounts');
};
});
答案 0 :(得分:0)
因为我按如下方式导入了React
import * as React from "react";
我需要在useEffect钩子前面加上React这样的前缀:
React.useEffect(() => {