Skip to content

Cannot read property '_notificationSystem' of null #128

@dparkar

Description

@dparkar

(new to React)

I am seeing the following error :

Uncaught TypeError: Cannot read property '_notificationSystem' of null
at _addNotification (notifier.jsx:11)
at Object.ReactErrorUtils.invokeGuardedCallback (ReactErrorUtils.js:69)
at executeDispatch (EventPluginUtils.js:85)
at Object.executeDispatchesInOrder (EventPluginUtils.js:108)
at executeDispatchesAndRelease (EventPluginHub.js:43)
at executeDispatchesAndReleaseTopLevel (EventPluginHub.js:54)
at Array.forEach ()
at forEachAccumulated (forEachAccumulated.js:24)
at Object.processEventQueue (EventPluginHub.js:254)
at runEventQueueInBatch (ReactEventEmitterMixin.js:17)
at Object.handleTopLevel [as _handleTopLevel] (ReactEventEmitterMixin.js:27)
at handleTopLevelImpl (ReactEventListener.js:72)
at ReactDefaultBatchingStrategyTransaction.perform (Transaction.js:143)
at Object.batchedUpdates (ReactDefaultBatchingStrategy.js:62)
at Object.batchedUpdates (ReactUpdates.js:97)
at dispatchEvent (ReactEventListener.js:147)

image

Here's how my code looks :

notifier.jsx :

import React, {Component} from 'react';
import NotificationSystem from 'react-notification-system';

export default class Notifier extends Component {
    
    _notificationSystem = null;

    _addNotification(event) {
        event.preventDefault();
        this._notificationSystem.addNotification({
          message: 'Notification message',
          level: 'success'
        });
      }

    componentDidMount() {
        this._notificationSystem = this.refs.notificationSystem;
      }

    render() {
        return (
            <div>
              <button onClick={this._addNotification}>Add notification</button>
              <NotificationSystem ref="notificationSystem" />
            </div>
            );
    }
}

elsewhere in component foo.jsx :

render() {
   return (
      <div className="notifier">
        <Notifier/>
      </div>
    );
}

Versions :

"react": "^15.6.2",
"react-dom": "^15.6.1",
"react-notification-system": "^0.2.16",
"react-router-dom": "^4.2.2"

Thanks for the help !

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions