저는 센서를 모니터링하기 위해 ReactJS에서 실시간 대시 보드 애플리케이션을 작성하는 중입니다. PHP에서 AutobahnJS + 웹 소켓을 사용하여 데이터를 스트리밍합니다.ReactJS : Transferring Props
이것은 구성 요소보기에서 내 대시 보드의 추상화입니다. Abstraction of dashboard in component view
Main.jsx :
class Main extends React.Component {
constructor(props) {
super(props)
}
componentDidMount() {
$(document).foundation();
var that = this;
var conn = new ab.Session('ws://xx.xxx.xxx.xx', function() {
conn.subscribe('', function(topic, data) {
console.log(data);
that.setState({
result: data
});
});
}, function() {
console.warn('WebSocket connection closed');
}, {'skipSubprotocolCheck': true});
}
render() {
return (
<div>
<div className="off-canvas-wrapper">
<div className="off-canvas-wrapper-inner" data-off-canvas-wrapper>
<div className="off-canvas position-right" data-position="right" id="offCanvas" data-off-canvas>
<SensorDetails/>
</div>
<div className="off-canvas-content" data-off-canvas-content>
<Nav/>
<div className="row">
<div className="columns medium-12 large 12">
{this.props.children}
</div>
</div>
</div>
</div>
</div>
</div>
);
}
};
module.exports = Main;
Main.jsx에서 BuildingList.jsx에 소품을 전달하는 적절한 방법은 무엇입니까?
{this.props.children}
이 작동하지만 난 예를 들어, 내 링크에 액세스 할 수 없습니다 해요
<Dashboard data={this.state.result}/>
로 : 난 대체 시도 계정 설정. 내 반응 라우터는 다음과 같이 설정됩니다.
<Router history={hashHistory}>
<Route path="/dashboard" component={Main} >
<Route path="/about" component={About} onEnter={requireLogin}/>
<Route path="/examples" component={Examples} onEnter={requireLogin}/>
<Route path="/accountSettings" component={AccountSettings} onEnter={requireLogin}/>
<IndexRoute component={Dashboard}/>
</Route>
<Route path="/" component={Login} onEnter={redirectIfLoggedIn}/>
</Router>
이 문제를 어떻게 해결할 수 있습니까? 감사.
감사합니다. Enjijar! 나는 두 가지 해결책을 모두 시도했지만 둘 중 어느 것도 작동하지 않습니다. 두 번째 솔루션의 경우 "App is not defined"오류가 발생합니다. –