mirror of
https://github.com/Stone-Red-Code/website.git
synced 2026-09-05 23:43:37 +02:00
refact(sidebar): move mobile state to context provider
This commit is contained in:
@@ -3,6 +3,8 @@ import React, { FC, useMemo, useState } from "react"
|
||||
export interface ISidebarContextInterface {
|
||||
current: number
|
||||
setCurrent: (index: number) => void
|
||||
openOnMobile: boolean
|
||||
setOpenOnMobile: (active: boolean) => void
|
||||
}
|
||||
|
||||
export const SidebarContext = React.createContext<ISidebarContextInterface | null>(
|
||||
@@ -11,13 +13,16 @@ export const SidebarContext = React.createContext<ISidebarContextInterface | nul
|
||||
|
||||
export const SidebarProvider: FC = ({ children }) => {
|
||||
const [current, setCurrent] = useState(0)
|
||||
const [openOnMobile, setOpenOnMobile] = useState(false)
|
||||
|
||||
const memoizedContextValue = useMemo(
|
||||
() => ({
|
||||
current,
|
||||
setCurrent,
|
||||
openOnMobile,
|
||||
setOpenOnMobile,
|
||||
}),
|
||||
[current, setCurrent]
|
||||
[current, setCurrent, openOnMobile, setOpenOnMobile]
|
||||
)
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user