[英]element refers to a value, but is being used as a type here
I have the following code:我有以下代码:
export const StateContext = createContext({});
const StoreProvider: any = StateContext.Provider;
export const StateProvider = ({ reducer, initialState, children }: any) => (
<StoreProvider value={useReducer(reducer: any, initialState: any)}>
{children}
</StoreProvider>
);
but TypeScript is throwing an error 'StoreProvider' refers to a value, but is being used as a type here.
但 TypeScript 抛出错误
'StoreProvider' refers to a value, but is being used as a type here.
- why? - 为什么? I assume its seeing it as a generic, but how to make it see as is needed?
我假设它把它看作是一个通用的,但如何让它看起来像需要的那样?
I got the same error on my project and solve the problem.我在我的项目中遇到了同样的错误并解决了问题。 Maybe your filename extension is ts, not tsx.
也许您的文件扩展名是 ts,而不是 tsx。 If you are using Parcel or so on, the compiler considers that the file doesn't use React.
如果您使用的是 Parcel 等,编译器会认为该文件没有使用 React。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.