this.prompt()
をTitleBar
からPortfolio
に渡したいとします。私はそれを正しい方法でやっていますか?データが1つのコンポーネントから次のコンポーネントに渡されないのはなぜですか?
var TitleBar = React.createClass({
render: function() {
return(
<div className="jumbotron">
<div className="container">
<kbd className="fullName">name name</kbd>
<button onClick={this.prompt} type="button" className="btn btn-primary portfolio">Portfolio</button>
<button type="button" className="btn btn-primary about">About</button>
<button type="button" className="btn btn-primary contact">Contact</button>
</div>
</div>
);
}
});
ReactDOM.render(<TitleBar/>, document.getElementById('firstBar'));
var Portfolio = React.createClass({
this.props.prompt(
alert("hi");
);
render: function() {
return(
<p className="text-primary">Portfolio</p>
);
}
});
ReactDOM.render(<Portfolio prompt={this.prompt}/>, document.getElementById('portfolio'));
はここに私のindex.js
ファイルです:
var TitleBar = React.createClass({
render: function() {
return(
<div className="jumbotron">
<div className="container">
<kbd className="fullName">name name</kbd>
<button onClick={this.prompt} type="button" className="btn btn-primary portfolio">Portfolio</button>
<button type="button" className="btn btn-primary about">About</button>
<button type="button" className="btn btn-primary contact">Contact</button>
</div>
</div>
);
}
});
ReactDOM.render(<TitleBar/>, document.getElementById('firstBar'));
var Portfolio = React.createClass({
this.props.prompt(
alert("hi");
);
render: function() {
return(
<p className="text-primary">Portfolio</p>
);
}
});
ReactDOM.render(<Portfolio prompt={this.prompt}/>, document.getElementById('portfolio'));
私の編集を掲載したばかりなので、なぜ私のページが空白になるのですか? – chompy
私はあなたの方法、特に最初のものが好きです。 – chompy
どのようなエラーが表示されますか?また、私はあなたが他のファイルを使用している両方のファイルに表示されません。また、インポートに関しては、ファイルに関連付けることができ、絶対的である必要はありません。したがって、あるファイルが別のファイルの隣にある場合は、 ''。/ file.js ''だけを実行できます。詳細は、この[page](http://exploringjs.com/es6/ch_modules.html)の「相対パス」を検索してください。 –