im using the useContext from react , i have add boolean state to context but when i use it in the component it's give me typeErro : the setState is not a function
what im doing wrong this is my code ?
// context file
import { createContext, useContext, Dispatch, SetStateAction } from 'react';
interface TasksContextType {
isSubmitLoading: boolean;
setIsSubmitLoading: Dispatch<React.SetStateAction<boolean>>;
}
export const TasksContext = createContext({} as TasksContextType);
export const useTasksContext = () => {
const context = useContext<TasksContextType>(TasksContext);
if (!context) {
throw new Error('useTasksContext should be used within a TasksContext');
}
return context;
};
the provider file
//provider file
import React, { FC, useState } from 'react';
import { TasksContext } from './TasksContext';
export const TasksProvider: FC = ({ children }) => {
const [isSubmitLoading, setIsSubmitLoading] = useState<boolean>(false);
return (
<TasksContext.Provider
value={{
isSubmitLoading,
setIsSubmitLoading,
}}
>
{children}
</TasksContext.Provider>
);
};
the component where i use the useContext
//component
const { setIsSubmitLoading, isSubmitLoading } = useTasksContext();
useEffect(() => {
setIsSubmitLoading(mutation.isLoading);
}, [mutation, setIsSubmitLoading]);