我有以下代码:
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.
-为什么?我以为它是通用的,但是如何使其按需显示呢?
答案 0 :(得分:0)
我在项目中遇到了相同的错误并解决了问题。 也许您的文件扩展名是ts,而不是tsx。 如果您使用的是Parcel等,编译器会认为该文件未使用React。