-
-
Notifications
You must be signed in to change notification settings - Fork 426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Map & Set to useLocalStorage control #309
Add Map & Set to useLocalStorage control #309
Conversation
const parsed = parseJSON(item) as T | ||
|
||
//considering that the initial value is a Map, convert object to map | ||
if(initialValue instanceof Map) { | ||
return new Map(Object.entries(parsed as Object)) as T | ||
} | ||
|
||
//considering that the initial value is a Set, convert the array to set | ||
if(initialValue instanceof Set) { | ||
return new Set(parsed as Array<any>) as T | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gonna write this here because I think it is more like to be a question on this pr than a part of it's description.
'Why not put this Map and Set creation logic inside parseJSON
function ? "
I did this way because I think that it was no good to add a new parameter to parseJSON
function just to say that it would be a Map or Set. Considering that is no more than this 2 instance checks I think that it would have no problem to stay this way, but, open for tips and discussions !
Hi, very usefull function |
finally someone did it 🙌🏻 |
Hi you all, good feature indeed. As the PR's base branch is outdated, I moved this code there #439. |
-> enable useLocalStorage hook to work with Map and Set
-> check instance types of
initialValue
to work with return type onreadValue
-> create
stringify
function to work separately with type checking and string buildissue: #308