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

Prevent useSnackbar from returning a new object on every call #223

Closed
wants to merge 1 commit into from
Closed

Prevent useSnackbar from returning a new object on every call #223

wants to merge 1 commit into from

Conversation

DASPRiD
Copy link

@DASPRiD DASPRiD commented Feb 11, 2020

At the moment, useSnackbar will return a new object on every call.

This causes a problem when using it in an effect and specifying it as a dependency (exhaustive-deps check will fail otherwise), as it will cause the effect to run every time the component renders, since React sees the snackbar object as changed.

By returning the context directly, the object should never change.

@iamhosseindhv
Copy link
Owner

@DASPRiD Would you be able to provide a simple reproduction with console log showing useEffect being called on every render.

@DASPRiD
Copy link
Author

DASPRiD commented Feb 17, 2020

I'm currently on vacation, will look into that after Feb 25.

@DASPRiD
Copy link
Author

DASPRiD commented Feb 28, 2020

Here is a simple test case:
https://codesandbox.io/s/focused-hodgkin-evq3u

By clicking the button, it causes the app to rerender. This in turn will, without my patch, cause the effect to rerun (see console).

iamhosseindhv added a commit that referenced this pull request Mar 5, 2020
@iamhosseindhv
Copy link
Owner

Sorry I messed up. my commit to fix a linting issue was supposed to be part of this PR, so github counts you as contributor of the repo.

Anyhow, Thanks for your contribution ❤️I'll publish the fix as v0.9.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants