Question : use state on local storage
Answered by : odd-oryx-by8uir8zvo0o
{"tags":[{"tag":"p","content":"local storage"},{"tag":"p","content":"<br>"},{"tag":"textarea","content":"const [user, setUser] = useState([], () => {\n const localData = localStorage.getItem('userData');\n return localData ? JSON.parse(localData) : [];\n});","code_language":"whatever"}]}
Source : https://stackoverflow.com/questions/60688411/assign-local-storage-to-react-state-react-hooks | Last Update : Wed, 12 Jul 23