useEffect Hook to Check User Details in Local Storage
If user token is in [Local Storage], save user details to state and to blogService.
useEffect(() => { const loggedUserJSON = window.localStorage.getItem('loggedBlogListAppUser') if (loggedUserJSON) { const user = JSON.parse(loggedUserJSON) setUser(user) blogService.setToken(user.token) }}, [])
Note -> empty array as the parameter of effect ensures the effect is executed only when the component rendered for the first time
Source -> Using the Effect Hook