gor181 / react-notification-system-redux

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

Can I re-render a notification? #63

Open mo-ib opened 6 years ago

mo-ib commented 6 years ago

I LOVE this library, very elegant. I want to use it beyond it's intended purpose as well, to display some bulk edit elements as I select them from a list. Is there a way to re-render the message prop so as I add elements, the message bosy updates? I'm trying something like this:

toggleRowsWithBulkEdit(item) {
  const rowsWithBulkEdit = toggleBulkEditItem(this.state.rowsWithBulkEdit, item)

  this.setState({rowsWithBulkEdit})

  const makeMessage = bulkEditProps => {
    console.log(bulkEditProps)
    return (
      <BulkEdit {...bulkEditProps}/>
    )
  }

  this.props.showNotification({
    title: 'hi',
    message: makeMessage({
      rowsWithBulkEdit,
    }),
    autoDismiss: 0,
    position: 'br',
    uid: 'bulkEditing',
  }, 'info')
}

and the console.log inside makeMessage is displaying the proper list, but obviously if I console log inside the BulkEdit component, it remains at 1.

Olliebaba commented 5 years ago

Instead of passing message, you can can pass a children prop:

  const config = {
    uid,
    title: `${message}`,
    position: 'br',
    autoDismiss: 0,
    dismissible: false,
    children: (
      <Message
        exportJobId={exportJobId}
        jobStatus={jobStatus}
        uid={uid} />
    ),
  }

  dispatch(success(config))

This Message component can be connected to the value either with redux or context api.

Another alternative is that you could store the notification UID, close that and then open a new one.