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

useless bind of arrow function #603

Open
jonenst opened this issue May 22, 2024 · 0 comments
Open

useless bind of arrow function #603

jonenst opened this issue May 22, 2024 · 0 comments

Comments

@jonenst
Copy link

jonenst commented May 22, 2024

Expected Behavior

SnackbarProvider code is simple

Current Behavior

SnackbarProvider code works but has useless bind or contextValue enqueueSnackbar
I stumbled on this while browsing the code
https://github.com/iamhosseindhv/notistack/blob/master/src/SnackbarProvider/SnackbarProvider.tsx#L51

export let enqueueSnackbar;

class SnackbarProvider extends Component<SnackbarProviderProps, State> {
    constructor(props: SnackbarProviderProps) {
        enqueueSnackbar = this.enqueueSnackbar;
        this.state = {
            contextValue: {
                enqueueSnackbar: this.enqueueSnackbar.bind(this),
        }}
    enqueueSnackbar = () => { ... }
}

since enqueueSnackbar is defined as an arrow function, you can't bind. It already has "this" to the instance of the class. That's why the global variable works without bind. the context value should be just se to enqueueSnackbar without binding. If I understood everything correctly.

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

No branches or pull requests

1 participant