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

Use with redux toolkit #280

Closed
Tsyklop opened this issue Nov 15, 2022 · 4 comments
Closed

Use with redux toolkit #280

Tsyklop opened this issue Nov 15, 2022 · 4 comments

Comments

@Tsyklop
Copy link

Tsyklop commented Nov 15, 2022

How to use this lib with redux-toolkit?

@diegoddox
Copy link
Owner

Should be possible, where are stuck?

@Tsyklop
Copy link
Author

Tsyklop commented Nov 16, 2022

@diegoddox In you example need call bindActionCreators function for actions.

I have some asyncThunk functions for displaing toasts:

import {actions as toastrActions} from 'react-redux-toastr'

export const toastError = createAsyncThunk('common/toast-error', (message, {dispatch}) => {
    if (!message || message.length <= 0) {
        return;
    }
    const toastr = bindActionCreators(toastrActions, dispatch)
    dispatch(toastr.error(message));
});

export const toastWarning = createAsyncThunk('common/toast-warning', (message, {dispatch}) => {
    if (!message || message.length <= 0) {
        return;
    }
    const toastr = bindActionCreators(toastrActions, dispatch)
    dispatch(toastr.warning(message));
});

export const toastSuccess = createAsyncThunk('common/toast-success', (message, {dispatch}) => {
    if (!message || message.length <= 0) {
        return;
    }
    const toastr = bindActionCreators(toastrActions, dispatch)
    dispatch(toastr.success(message));
});

export const toastDismiss = createAsyncThunk('common/toast-dismiss', (toastId, {dispatch}) => {
    if (!toastId) {
        return;
    }
    const toastr = bindActionCreators(toastrActions, dispatch)
    dispatch(toastr.dismiss(toastId));
});

And i need every time in createAsyncThunk call bindActionCreators function?

@diegoddox
Copy link
Owner

Any reason why u don't wanna use the event-emitter?

@diegoddox
Copy link
Owner

Closing, hope you found a solution for it

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

2 participants