Fixed some potential problem with the uselocalstorage
This commit is contained in:
		
							parent
							
								
									80f78d9940
								
							
						
					
					
						commit
						a780db9b0f
					
				| @ -10,7 +10,7 @@ export default function useStateWithLocalStorage<T>( | ||||
|   useEffect(() => { | ||||
|     try { | ||||
|       const item = localStorage.getItem(key); | ||||
|       if (item !== undefined && item !== null) { | ||||
|       if (item !== "undefined" && item !== null) { | ||||
|         setValue(JSON.parse(item) as T); | ||||
|       } else { | ||||
|         setValue(initialValue); | ||||
| @ -23,7 +23,7 @@ export default function useStateWithLocalStorage<T>( | ||||
|   }, [initialValue, key]); | ||||
| 
 | ||||
|   useEffect(() => { | ||||
|     localStorage.setItem(key, JSON.stringify(value)); | ||||
|     if (value !== undefined) localStorage.setItem(key, JSON.stringify(value)); | ||||
|   }, [value, key]); | ||||
| 
 | ||||
|   return [value, setValue]; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 DrMint
						DrMint