I am trying to make a context with hooks in react with typescript like this:
// StateGlobalContext.ts
import React, { Dispatch, ReactNode, SetStateAction } from "react";
export interface StateGlobalContextType {
loading: boolean
setLoading: Dispatch<SetStateAction<boolean>>
}
export const StateGlobalContext = React.createContext<StateGlobalContextType>({} as StateGlobalContextType);
export default function StateGlobalProvider({ children: ReactNode }): React.FC<ReactNode> {
const [loading, setLoading] = React.useState<boolean>(false);
return (
<StateGlobalContext.Provider value={{ loading, setLoading }}>
{props.children}
</StateGlobalContext.Provider>
)
}
But for some reason i don't know why, return get problem like this
Type '{}' is missing the following properties from type 'ReactElement<any, any>': type, props, key
and i cannot declare StateGlobalContext.Provider, the error message like this
Cannot find namespace 'StateGlobalContext'