tabs context created

This commit is contained in:
anovazzi1 2023-02-20 16:48:15 -03:00
commit bf678e5f86
2 changed files with 50 additions and 0 deletions

View file

@ -0,0 +1,41 @@
import { createContext, useState } from "react";
type flow={name:string,id:string,flow:any}
type TabsContextType={
tabIndex:number;
setTabIndex:(index:number)=>void;
flows:Array<flow>
removeFlow:(index:number)=>void;
addFlow:(newFlow:flow)=>void;
}
const TabsContextInitialValue = {
tabIndex : 0,
setTabIndex:(index:number)=>{},
flows:[],
removeFlow:(index:number)=>{},
addFlow:(newFlow:flow)=>{}
}
export const TabsContext = createContext<TabsContextType>(TabsContextInitialValue)
export function TabsProvider({children}){
const [tabIndex,setTabIndex] = useState(0)
const [flows,setFlows] = useState<Array<flow>>([])
function removeFlow(index:number){
let newFlows = flows
newFlows.splice(index)
setFlows(newFlows)
}
function addFlow(newFlow:flow){
setFlows([...flows,newFlow])
}
return(
<TabsContext.Provider value={{tabIndex,setTabIndex,flows,removeFlow,addFlow}}>
{children}
</TabsContext.Provider>
)
}