localstorage is not defined nextjs

Solutions on MaxInterview for localstorage is not defined nextjs by the best coders in the world

showing results for - "localstorage is not defined nextjs"
Anastasia
07 Jul 2017
1// components
2function Storage(props) {
3	const LocalStorage = ({ type, keys, value, onLocalStorage }) => {
4		switch (type) {
5			case 'set':
6				keys !== undefined && window.localStorage.setItem(keys, value)
7				break
8			case 'get':
9				keys !== undefined && onLocalStorage(window.localStorage.getItem(keys))
10				break
11			case 'remove':
12				keys !== undefined && window.localStorage.removeItem(keys)
13				break
14			case 'clear':
15				keys !== undefined && window.localStorage.clear()
16				break
17			default:
18				alert('localStorage type undefined')
19				break
20		}
21	}
22
23	return <div>{LocalStorage(props)}</div>
24}
25
26export default Storage
27
28// pages component
29import dynamic from 'next/dynamic'
30
31const LocaStorage = dynamic(() => import('../components/Storage'), { ssr: false })
32
33function Home() {
34	const getLocalStorage = (val) => console.log(val)
35
36	return (
37		<>
38			<LocaStorage type={'set'} keys={'name'} value={'My name is restu wahyu saputra'} />
39			<LocaStorage type={'get'} keys={'name'} onLocalStorage={getLocalStorage} />
40		</>
41	)
42}
43
44export default Home
queries leading to this page
referenceerror 3a localstorage is not defined nextjsreferenceerror 3a localstorage is not defined next jsnextjs referenceerror 3a localstorage is not definedlocalstorage is not defined in next jsnextjs localstorage is not definednext js localstorage is not definedserver error referenceerror 3a localstorage is not defined next js 3a localstorage is not defined next jsnextjs referenceerror 3a localstorage is not definedlocalstorage not defined nextjsnext js local storage is not definedreferenceerror localstorage is not defined nextjsnext localstorage is not definedreferenceerror 3a localstorage is not defined in next jsnextjs localstorage not definednext js localstorage is not definedlocalstorage is not defined nextjs reduxlocalstorage is not defined i nextreferenceerror 3a localstorage is not defined this error happened while generating the page nextjsnextjs is showing localstorage is not defined on reduxerror 3a localstorage is not defined nextjsreferenceerror 3a localstorage is not defined next jswindow localstorage is not defined next jsserver error referenceerror localstorage is not defined nextjsnextjs localstorage is not defined solutionlocalstorage is not defined next jsnext js localstorage is not definedlocalstorage is not defined in nextjsreferenceerror 3a localstorage is not defined nextreferenceerror 3a localstorage is not defined next js functional componentlocal storage is not defined nextjsnextjs is showing localstorage is not definedlocalstorage is not defined next tslocalstorage is not defined nextjsnext js referenceerror 3a localstorage is not definedreferenceerror localstorage is not defined next jslocalstorage is not defined nextjs