gor181 / react-notification-system-redux

Redux wrapper for react-notification-system
MIT License
324 stars 59 forks source link

Error when passing a function as argument #52

Open bflannery opened 7 years ago

bflannery commented 7 years ago

Following you example and getting an error when trying to pass a function as an argument to the dispatch call.

Your Example:

    setTimeout(() => {
      this.context.store.dispatch(fn(notificationOpts));
    }, timeout);
  }

  handleClick() {
    this.dispatchNotification(success, 250);
    this.dispatchNotification(error, 500);
    this.dispatchNotification(warning, 750);
    this.dispatchNotification(info, 1000);
  }

When I try this on my machine I get an error saying: Uncaught TypeError: _reactNotificationSystemRedux2.default.fn is not a function

Below is my code:

import Notifications, { success, error, warning, info, removeAll } from 'react-notification-system-redux';

export const notifyErrorAction = (fn, notification) => dispatch => {
  dispatch(Notifications.fn({
      title: notification.title,
      message: notification.message,
      position: 'tr',
      autoDismiss: 5000,
    })
  )
}

const notification = {
  title: 'Error',
  message: 'There is an error'
}

this.props.notifyError(error, notification)

The this.props.notifyError() is being called and does pass the error() to notifyErrorAction(). When I log out fn in the notifyErrorAction() I get:

ƒ error(opts) {
  return show(opts, 'error');
} 

I'm not sure if there is a step I'm missing. The only difference I can see is that you called dispatchNotification with a timeout. Was this just for effect or does the timing matter?