2
votes

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. - why? I assume its seeing it as a generic, but how to make it see as is needed?

1
I believe this will help: useReducer((reducer as any), (initialState as any))Viktor Zagoruyko

1 Answers

5
votes

I got the same error on my project and solve the problem. Maybe your filename extension is ts, not tsx. If you are using Parcel or so on, the compiler considers that the file doesn't use React.