mirror of
https://github.com/Stone-Red-Code/website.git
synced 2026-09-04 09:15:58 +02:00
29 lines
600 B
TypeScript
29 lines
600 B
TypeScript
import React, { FC, useMemo, useState } from "react"
|
|
|
|
export interface ISidebarContextInterface {
|
|
current: number
|
|
setCurrent: (index: number) => void
|
|
}
|
|
|
|
export const SidebarContext = React.createContext<ISidebarContextInterface | null>(
|
|
null
|
|
)
|
|
|
|
export const SidebarProvider: FC = ({ children }) => {
|
|
const [current, setCurrent] = useState(0)
|
|
|
|
const memoizedContextValue = useMemo(
|
|
() => ({
|
|
current,
|
|
setCurrent,
|
|
}),
|
|
[current, setCurrent]
|
|
)
|
|
|
|
return (
|
|
<SidebarContext.Provider value={memoizedContextValue}>
|
|
{children}
|
|
</SidebarContext.Provider>
|
|
)
|
|
}
|