我正在尝试使用此react-notification-system
,它会在您的顶级HTML级别上写下您的<NotificationSystem ref="notificationSystem" />
,如下所示:
<div className="wrapper">
<NotificationSystem ref="notificationSystem" style={style} />
<Sidebar {...this.props} />
<div id="main-panel" className="main-panel" ref="mainPanel">
<Header {...this.props} />
<Switch>
{dashboardRoutes.map((prop, key) => {
if (prop.name === "Notifications")
return (
<Route
path={prop.path}
key={key}
render={routeProps => (
<prop.component
{...routeProps}
handleClick={this.handleNotificationClick}
/>
)}
/>
);
if (prop.redirect)
return <Redirect from={prop.path} to={prop.to} key={key} />;
return (
<Route path={prop.path} component={prop.component} key={key} />
);
})}
</Switch>
<Footer />
</div>
</div>
虽然我在父组件中编写ref
,但如何在组件树中的子组件中访问它?我的意思是,我正在尝试在子组件中执行this.refs.notificationSystem
并且它正在返回null