refact(sidebar): move mobile state to context provider

This commit is contained in:
Jean-Philippe Sirois
2020-01-17 23:17:05 -05:00
parent 61a8aa07fd
commit ea57ea7815
2 changed files with 45 additions and 27 deletions
+6 -1
View File
@@ -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 (