refactor typesContext
This commit is contained in:
parent
60eccb274d
commit
019af743b7
1 changed files with 37 additions and 30 deletions
|
|
@ -1,15 +1,14 @@
|
||||||
import { ReactEventHandler, createContext, useState } from "react";
|
import { createContext, useState } from "react";
|
||||||
import { ReactFlowInstance } from "reactflow";
|
import { ReactFlowInstance } from "reactflow";
|
||||||
|
|
||||||
type typesContextType=
|
//context to share types adn functions from nodes to flow
|
||||||
{
|
type typesContextType = {
|
||||||
reactFlowInstance: ReactFlowInstance;
|
reactFlowInstance: ReactFlowInstance;
|
||||||
setReactFlowInstance: any;
|
setReactFlowInstance: any;
|
||||||
deleteNode: (idx: number) => void;
|
deleteNode: (idx: number) => void;
|
||||||
types: {};
|
types: {};
|
||||||
setTypes: (newState: {}) => void;
|
setTypes: (newState: {}) => void;
|
||||||
|
};
|
||||||
}
|
|
||||||
|
|
||||||
const initialValue = {
|
const initialValue = {
|
||||||
reactFlowInstance: null,
|
reactFlowInstance: null,
|
||||||
|
|
@ -17,7 +16,7 @@ const initialValue= {
|
||||||
deleteNode: () => {},
|
deleteNode: () => {},
|
||||||
types: {},
|
types: {},
|
||||||
setTypes: () => {},
|
setTypes: () => {},
|
||||||
}
|
};
|
||||||
|
|
||||||
export const typesContext = createContext<typesContextType>(initialValue);
|
export const typesContext = createContext<typesContextType>(initialValue);
|
||||||
|
|
||||||
|
|
@ -30,8 +29,16 @@ export function TypesProvider({children}){
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<typesContext.Provider value={{ types, setTypes, reactFlowInstance, setReactFlowInstance, deleteNode}}>
|
<typesContext.Provider
|
||||||
|
value={{
|
||||||
|
types,
|
||||||
|
setTypes,
|
||||||
|
reactFlowInstance,
|
||||||
|
setReactFlowInstance,
|
||||||
|
deleteNode,
|
||||||
|
}}
|
||||||
|
>
|
||||||
{children}
|
{children}
|
||||||
</typesContext.Provider>
|
</typesContext.Provider>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue