make use of useCallback

This commit is contained in:
Kim, Jimin 2022-01-22 11:44:25 +09:00
parent 8388bb3399
commit 2feeab9b2b

View file

@ -1,4 +1,4 @@
import { useState } from "react"
import { useCallback, useState } from "react"
import styled, { css } from "styled-components"
import ReactTooltip from "react-tooltip"
import { isMobile } from "react-device-detect"
@ -80,12 +80,10 @@ const SidebarWrap = styled.div`
const Sidebar = () => {
const [isSidebarOpen, setSidebarOpen] = useState(false)
// for some reason this.setState only works if this is an arrow function
const toggleSidebar = () => {
const toggleSidebar = useCallback(() => {
setSidebarOpen((prev) => !prev)
document.body.style.overflow = isSidebarOpen ? "" : "hidden"
}
}, [isSidebarOpen])
return (
<>