2016-10-17 4 views
1

현재 반응 알림을 구현 중이지만 Cannot read property 'preventDefault' of undefined이라는 오류가 발생하여 _addNotification에 전달되는 이벤트가 정의되지 않았다고 생각됩니다.반응 알림을 찾을 수 없습니다.

_handleSuccess: function(data, status, jqXHR) { 
    this._addNotification() 
    this.setState({ 
    errors: {}, 
    loading: false 
    }); 
}, 
_notificationSystem: null, 

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

_componentDidMount: function() { 
    this._notificationSystem = this.refs.notificationSystem; 
}, 

_getNotificationSystemInstance: function() { 
    return this 
}, 

답변

2

문제는 여기에 당신이 어떤 매개 변수없이이 기능 그것이 event PARAM을 기대하는 것을 _addNotification를 호출되어있다.

그것은 당신이 그런 경우가 있다면 당신이이 경우에 대한 event 목적이없는, 따라서 당신도 event.preventDefault()를 제거하거나 eventpreventDefault 함수를 호출하기 전에 존재 여부를 확인하는 API 서비스에서 데이터를로드하는 나에게 보이는

. 당신은 단추 또는 링크에서 _addNotification를 호출하는 경우

_addNotification: function(event) { 
     event && event.preventDefault(); // <--- Check if event exist! 
     this._notificationSystem.addNotification({ 
     message: 'Notification message', 
     level: 'success', 
     position: 'bc' 
     }); 
}, 

, 당신은 preventDefault를 호출 할 필요가 없습니다. 따라서 수표를 제거하는 대신 수표를 추가하는 것이 좋습니다.

행운을 빈다.

+0

감사합니다. 이것으로 문제가 해결되지만, '속성을 읽을 수 없습니다'라는 addNotification 'of null'이라는 메시지가 나오는데 이는 null _notificationSystem에 알림을 추가하지 않는다는 것을 의미합니다. 그러나 이는 문서 [여기] (https://github.com/igorprado/react-notification-system#creating-a-notification)에 반하는 것으로 보입니다. 이것은 또한 빠른 수정이거나 자신의 질문을받을 만한지 확실하지 않습니다. –

관련 문제