March 14, 2022
mongoose에서 생성한 데이터를 populate해서 가져오는 방법
let user = await User.create({ ... })
user = await user.populate('company').execPopulate()
외부 돔을 클릭했을때 모달을 닫는 방법
import { useState, useRef, useEffect } from 'react'
export const useVisible = initialIsVisible => {
const [isVisible, setIsVisible] = useState(initialIsVisible)
const ref = useRef(null)
const ClickOutside = event => {
if (ref.current && !ref.current.contains(event.target)) {
console.log('응애')
setIsVisible(false)
}
}
useEffect(() => {
document.addEventListener('click', ClickOutside, true)
return () => {
document.removeEventListener('click', ClickOutside, true)
}
}, [])
return [ref, isVisible, setIsVisible]
}