Nice trick, but I think it would make more sense to use useEffect method, did you try it?
useEffect
useEffect(function() { console.log(window.localStorate); },[]);
window.localStorage (spelling)
useEffect(function() { console.log(window.localstorage); },[]);
Because some time we need to copy and paste code, and after code doesn't work after pasting so developers 😯😯😯😯😯.
Your Code have some mistakes check out this 👍
You may find yourself in a situation where you need access to localStorage outside a react component. In that case useEffect cannot help.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Nice trick, but I think it would make more sense to use
useEffect
method, did you try it?window.localStorage (spelling)
Because some time we need to copy and paste code, and after code doesn't work after pasting so developers 😯😯😯😯😯.
Your Code have some mistakes check out this 👍
You may find yourself in a situation where you need access to localStorage outside a react component. In that case useEffect cannot help.