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:
parent
7c177a9930
commit
5222775c56
2 changed files with 27 additions and 0 deletions
21
src/frontend/src/contexts/storeContext.tsx
Normal file
21
src/frontend/src/contexts/storeContext.tsx
Normal 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>
|
||||
);
|
||||
}
|
||||
6
src/frontend/src/types/contexts/store.ts
Normal file
6
src/frontend/src/types/contexts/store.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import { FlowType } from "../flow";
|
||||
|
||||
export type storeContextType = {
|
||||
savedFlows: { [key: string]: FlowType };
|
||||
setSavedFlows: (newState: { [key: string]: FlowType }) => void;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue