Skip to content

Commit

Permalink
okk
Browse files Browse the repository at this point in the history
  • Loading branch information
rosiechen1005@ucla.edu committed Mar 4, 2024
1 parent 3c13456 commit 6cd40c8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/components/useLocalStorage 2.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { useState, useEffect, Dispatch, SetStateAction } from 'react';

function getStorageValue<T>(key: string, defaultValue: T): T {
// getting stored value
const saved = localStorage.getItem(key);
const initial = saved ? JSON.parse(saved) : null;
return initial !== null ? initial : defaultValue;
}

export function useLocalStorage<T>(
key: string,
defaultValue: T
): [T, Dispatch<SetStateAction<T>>] {
const [value, setValue] = useState<T>(() => {
return getStorageValue(key, defaultValue);
});

useEffect(() => {
// storing input name
localStorage.setItem(key, JSON.stringify(value));
}, [key, value]);

return [value, setValue];
}
4 changes: 4 additions & 0 deletions src/styles/Home.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@600&display=swap');

body.home {
overflow: hidden;
}

.home-container {
//background-color: #fef2e7;
height: 100vh;
Expand Down
2 changes: 1 addition & 1 deletion src/styles/Mario.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

@media screen and (max-width: 1200px) {
.mario-image {
bottom: 10%;
bottom: 38px;
height: auto;
width: 6%;
}
Expand Down

0 comments on commit 6cd40c8

Please sign in to comment.