generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make navigation bar collapsible (#527)
![Screenshot 2023-10-30 at 11 35 38 AM](https://github.com/TBD54566975/ftl/assets/51647/dea16420-1d16-4639-b479-5231654bb29e) ![Screenshot 2023-10-30 at 11 35 41 AM](https://github.com/TBD54566975/ftl/assets/51647/622cb1d7-93ee-4812-a94a-aed615027979)
- Loading branch information
1 parent
496e516
commit c0ceb23
Showing
4 changed files
with
60 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,15 @@ | ||
import React, { useEffect, useState } from 'react' | ||
import { useEffect, useState } from 'react' | ||
|
||
export default function useLocalStorage( | ||
key: string, | ||
initialValue: string, | ||
): [string, React.Dispatch<React.SetStateAction<string>>] { | ||
const [value, setValue] = useState<string>(() => { | ||
export default function useLocalStorage<T>(key: string, initialValue: T) { | ||
const [value, setValue] = useState<T>(() => { | ||
const jsonValue = localStorage.getItem(key) | ||
if (jsonValue != null) return JSON.parse(jsonValue) as string | ||
if (jsonValue != null) return JSON.parse(jsonValue) as T | ||
return initialValue | ||
}) | ||
|
||
useEffect(() => { | ||
localStorage.setItem(key, JSON.stringify(value)) | ||
}, [key, value]) | ||
|
||
return [value, setValue] | ||
return [value, setValue] as const | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters