make use of useCallback
This commit is contained in:
parent
8388bb3399
commit
2feeab9b2b
1 changed files with 3 additions and 5 deletions
|
@ -1,4 +1,4 @@
|
||||||
import { useState } from "react"
|
import { useCallback, useState } from "react"
|
||||||
import styled, { css } from "styled-components"
|
import styled, { css } from "styled-components"
|
||||||
import ReactTooltip from "react-tooltip"
|
import ReactTooltip from "react-tooltip"
|
||||||
import { isMobile } from "react-device-detect"
|
import { isMobile } from "react-device-detect"
|
||||||
|
@ -80,12 +80,10 @@ const SidebarWrap = styled.div`
|
||||||
|
|
||||||
const Sidebar = () => {
|
const Sidebar = () => {
|
||||||
const [isSidebarOpen, setSidebarOpen] = useState(false)
|
const [isSidebarOpen, setSidebarOpen] = useState(false)
|
||||||
|
const toggleSidebar = useCallback(() => {
|
||||||
// for some reason this.setState only works if this is an arrow function
|
|
||||||
const toggleSidebar = () => {
|
|
||||||
setSidebarOpen((prev) => !prev)
|
setSidebarOpen((prev) => !prev)
|
||||||
document.body.style.overflow = isSidebarOpen ? "" : "hidden"
|
document.body.style.overflow = isSidebarOpen ? "" : "hidden"
|
||||||
}
|
}, [isSidebarOpen])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue