This is my original code
import Cookies from 'js-cookie'
const getUser = () => {
  const {user} = Cookies.getJSON('user')
  if (user) return user
}
I got user is undefined error because user cookie doesn't exist.
I have to change it to
const getUser = () => {
  const cookie = Cookies.getJSON('user')
  if (!cookie) return false
  if (cookie.user) return cookie.user
}
Is there any more elegant way to prevent undefined error when doing desturcturing?
 
     
    