You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
714 B
24 lines
714 B
import { createContext, useContext } from "react";
|
|
import { type Todo, useTodos } from "./useTodos";
|
|
|
|
type TodosContextValue = ReturnType<typeof useTodos>;
|
|
|
|
const TodosContext = createContext<TodosContextValue | null>(null);
|
|
|
|
export function TodosProvider({ children }: { children: React.ReactNode }) {
|
|
console.log("[TODO_PROVIDER] MOUNTED!");
|
|
const store = useTodos();
|
|
return (
|
|
<TodosContext.Provider value={store}>{children}</TodosContext.Provider>
|
|
);
|
|
}
|
|
|
|
export function useTodosCtx(): TodosContextValue {
|
|
const ctx = useContext(TodosContext);
|
|
if (!ctx) {
|
|
throw new Error("use TodosCtx must be used within <TodosProvider>");
|
|
}
|
|
return ctx;
|
|
}
|
|
|
|
export type { Todo };
|
|
|