![](/img/trans.png)
[英]'ItemIsLoading' on refers to a type, but is being used as a value here
[英]element refers to a value, but is being used as a type here
我有以下代碼:
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>
);
但 TypeScript 拋出錯誤'StoreProvider' refers to a value, but is being used as a type here.
- 為什么? 我假設它把它看作是一個通用的,但如何讓它看起來像需要的那樣?
我在我的項目中遇到了同樣的錯誤並解決了問題。 也許您的文件擴展名是 ts,而不是 tsx。 如果您使用的是 Parcel 等,編譯器會認為該文件沒有使用 React。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.