puranjayjain / react-materialui-notifications

Spec compliant notifications for react and material ui users
https://puranjayjain.github.io/react-materialui-notifications/
MIT License
251 stars 36 forks source link

Call setState after or forceUpdate once a notification was added #128

Closed DevAlien closed 7 years ago

DevAlien commented 7 years ago

I tried this library and at first I could not see the notifications. Looking at the code I found out that you are using a global (scoped) variable to keep track of the notifications called notifications

The problem is that when you modify that, the component will NOT rerender automatically. Normally this is done using setState and then you would read directly from the state. In this case I think you have to force the update somehow.

In your demo it works just because you are incrementing a counter after you ccreated a new notification.

this.setState({
      count: ++this.state.count
    })

This will update the component and as well all its subcomponents (in this case the notification component will get updated because it is a child)

puranjayjain commented 7 years ago

@DevAlien yes I agree with you I'm thinking of rewriting the component but I am putting it on hold till react fiber is launched with its awesomeness. I'll resume my efforts to improvise the component with a major version and api update (possibly the nougat update as well)

DevAlien commented 7 years ago

Ok, I've PRd some fixes, if that could be released would be great. if not I'd have to release a fork myself.