我收到此错误:
导出的变量“useAuth”具有或正在使用外部模块“c:/Users/PC/Desktop/my Practices/react-course-part2-starter/src/state-management/Contexts/authContext”中的名称“AuthcontextType”,但不能被命名.ts(4023)
const useAuth: () => AuthcontextType
当我想运行此文件中的代码时:
import { useContext } from "react";
import AuthContext from "../Contexts/authContext";
const useAuth = () => useContext(AuthContext);
export default useAuth
这是我的
AuthContext
文件:
import React, { Dispatch } from "react";
import { authAction } from "../Reducers/authReducer";
interface AuthcontextType {
user:string,
dispatch:Dispatch<authAction>
}
const AuthContext= React.createContext<AuthcontextType> ({} as AuthcontextType)
export default AuthContext
有人知道我该如何解决这个问题吗?
我认为你也必须导入 authcontexttype 。
import AuthContext, { AuthcontextType } from "../Contexts/authContext";