-
Notifications
You must be signed in to change notification settings - Fork 70
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
Fixed restore_votes not update MyVotes #2991, #2986 #3868
base: dev
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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.
Hey! Nice hook logic!
Although I have a question. I don't see any other usage of this hook beside changes in local storage. Could we maybe instead of creating a new hook to dispatch new events, improve useLocalStorage
logic to capture changes to itself from other places?
Here is a similar solution to yours, but only on local storage. Link
I tried to migrate customEvent inside useLocalStorage() hook. it applies the storage updated event to all states which uses same storage key. Please check and give me your feedback |
6b6768c
to
d301b49
Compare
packages/ui/src/council/modals/VoteForCouncil/VoteForCouncilSuccessModal.tsx
Outdated
Show resolved
Hide resolved
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.
Really nice solution 🎩
Just to 2 details:
return () => { | ||
document.removeEventListener(`storage_event_${key}`, handleEventOnce) | ||
} | ||
}, []) |
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.
I'm not sure if the key is ever changed somewhere in the code base, but to at least be consistent with other hooks dependencies called here:
}, []) | |
}, [key]) |
document.removeEventListener(`storage_event_${key}`, handleEventOnce) | ||
} | ||
}, []) | ||
|
||
const dispatch = useCallback( | ||
(setStateAction: T | ((prevState?: T) => T)) => { | ||
const value = isFunction(setStateAction) ? setStateAction(getItem(key)) : setStateAction | ||
setState(value) |
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.
Just to prevent redundant re-renders:
setState(value) |
@chrlschwb why did we decide to close it? Looks like solution was nice and we were close to resolution.. if its due to no access to the branch @thesan could take this over at some point. Please let us know! |
Added customEvent mechanism inside the pioneer and refresh the Election page after Restore Votes clicked.
Fixed #2991, #2986