feat(storeContext): add storeContext to manage and share user components and their updates

feat(storeContext): create storeProvider component to provide the store context to child components
feat(storeContext): define storeContextType to specify the shape of the store context data
This commit is contained in:
anovazzi1 2023-10-24 20:07:42 -03:00
commit 5222775c56
2 changed files with 27 additions and 0 deletions

View file

@ -0,0 +1,21 @@
import { createContext, useState } from "react";
import { storeContextType } from "../types/contexts/store";
import { FlowType } from "../types/flow";
//store context to share user components and update them
const initialValue = {
savedFlows: {},
setSavedFlows: () => {},
};
export const StoreContext = createContext<storeContextType>(initialValue);
export function storeProvider({ children }) {
const [savedFlows, setSavedFlows] = useState<{ [key: string]: FlowType }>({});
return (
<StoreContext.Provider value={{ savedFlows, setSavedFlows }}>
{children}
</StoreContext.Provider>
);
}

View file

@ -0,0 +1,6 @@
import { FlowType } from "../flow";
export type storeContextType = {
savedFlows: { [key: string]: FlowType };
setSavedFlows: (newState: { [key: string]: FlowType }) => void;
};