Skip to content
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

Watch changes on storage and change state (closes #27) #30

Merged
merged 5 commits into from
Nov 24, 2019
Merged

Watch changes on storage and change state (closes #27) #30

merged 5 commits into from
Nov 24, 2019

Conversation

VitorLuizC
Copy link
Contributor

@VitorLuizC VitorLuizC commented Oct 27, 2019

I added a listener on storage that runs when modifying storage in another window or tab and an effect that runs on all cycles. Both change state if storage changes occur.

closes #27


useEffect(() => {
window.addEventListener('storage', handleStorage);
return () => window.removeEventListener('storage', handleStorage);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If value changes, causing handleStorage callback to change, will removeEventListener still work here then? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will remove and append again in the next cycle.

@dance2die
Copy link
Owner

Thank you @VitorLuizC for the PR (turn off notifications w/ checking 😓) and @Svish for the review.
I will check test the PR soon I get the chance (weekend latest).

@dance2die dance2die merged commit c43a571 into dance2die:master Nov 24, 2019
@dance2die
Copy link
Owner

Thank you again, @VitorLuizC.
The change is implemented in v3.4.1

@dance2die
Copy link
Owner

@all-contributors please add @Svish for review

@allcontributors
Copy link
Contributor

@dance2die

I've put up a pull request to add @Svish! 🎉

@Svish
Copy link

Svish commented Nov 24, 2019

@dance2die Really not sure my question counts as a contribution, but up to you guys, hehe 😛

@dance2die
Copy link
Owner

dance2die commented Nov 24, 2019

You were able to come up with the question because you read the code, spending your own time @Svish.
No matter how small a contribution is, it is still to be recognized/credited 😄

And also the question was insightful, as I was wondering about it as well.

@dance2die dance2die added the enhancement New feature or request label Nov 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New feature -> watch localstorage??
3 participants