Add save function
This commit is contained in:
14
lib/commands/ContextProvider.tsx
Normal file
14
lib/commands/ContextProvider.tsx
Normal file
@@ -0,0 +1,14 @@
|
||||
import { createContext, useContext } from "react";
|
||||
import type { PropsWithChildren } from "react";
|
||||
import { CommandInterface } from ".";
|
||||
import type { ContentList } from "../content/types";
|
||||
import type { CommandInterfaceCallbacks } from "./types";
|
||||
|
||||
const commandInterface = new CommandInterface();
|
||||
const CommandContext = createContext(commandInterface);
|
||||
const setCommandCallbacks = (callbacks: CommandInterfaceCallbacks) => commandInterface.callbacks = {...commandInterface.callbacks, ...callbacks};
|
||||
const setContents = (content: ContentList) => commandInterface.content = content;
|
||||
const useCommands = () => ({cmdContext: useContext(CommandContext), updateCallbacks: setCommandCallbacks, setContents});
|
||||
const CommandsProvider = (props: PropsWithChildren<{}>) => <CommandContext.Provider value={commandInterface} {...props} />;
|
||||
|
||||
export { CommandsProvider, useCommands };
|
||||
Reference in New Issue
Block a user