-
-
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
useSessionStorage improvements #276
Conversation
Which happen when session storage is updated for a different key.
ada583f
to
1266f5b
Compare
} | ||
}, [initialValue, key]) | ||
|
||
// State to store our value | ||
// Pass initial state function to useState so logic is only executed once | ||
const [storedValue, setStoredValue] = useState<T>(readValue) | ||
// create a new empty object to keep track of the identity of the hook | ||
const [source] = useState({}) |
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.
@juliencrn do you think it worthwhile to extract the creation of the empty object into a function so that it isn't created on each render?
1266f5b
to
3b72152
Compare
const getInitialValue = () => | ||
initialValue instanceof Function ? initialValue() : initialValue |
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.
@juliencrn or maybe memo-ize the initialValue so that we guarantee it only ever gets evaluated once?
This PR has 3 changes for the
useSessionStorage
hook:I love the library! Please let me know how I can improve the PR for your approval!