Ich habe eine App wie diese, und reagieren Meldungs-System verwenden möchten,Reagieren Benachrichtigungssystem
Und ich bin gespannt auf 1, was ist es möglich, über die Meldung zu machen, wenn etwas in Testcomponent passiert?
Mit anderen Worten, wenn in TestComponent etwas passiert, wie Elternkomponente in App.js aufrufen?
App.js hat eine Routing-System
xyz.com/test
<Route path='/test' component={TestComponent} />
App.js
export class App extends Component {
(...)
<Navbar/>
<Footer />
<TestComponent/>
<ToastNotif
ref="ToastNotifRef"
toastNotifStatus={this.state.toastNotifStatus}/>
(...)
ToastNotif.js
class ToastNotif extends Component {
constructor(props){
super(props);
this.state = {
toastNotifStatus: this.props.toastNotifStatus
}
}
componentDidMount(){
this.notificationSystem = this.refs.notificationSystem;
}
componentWillReceiveProps(newProps) {
const {notificationList} = newProps;
console.log('componentWillReceiveProps', newProps);
const {removeNotification} = this.props;
if(newProps.toastNotifStatus==='deleted'){
this.notificationSystem.addNotification({
title: "xxx!",
message: 'xxx'
level: 'success',
autoDismiss: 0,
position: 'bl'
});
}
}
render() {
console.log('toastnotifstatus (render)',this.state.toastNotifStatus)
return (
<div className="notification-component-wrapper">
<NotificationSystem ref="notificationSystem"/>
</div>
)
}
}
export default ToastNotif;