のプロパティ「SETSTATE」を読み取ることができません3つの異なる見出しをクリックすると、その見出しに固有の特定のテンプレートがレンダリングされます。これは私にこのエラー与えた私が現在使用しているコードです:さらにキャッチされない例外TypeError:</p> <blockquote> <p>Uncaught TypeError: Cannot read property 'setState' of null.</p> </blockquote> <p>を基本的に私はあるやろうとしています、ユーザーがクリックすることができます:私が述べた反応の使用に新たなんだと問題に遭遇してきたヌル
class Selection extends React.Component {
constructor(props) {
super(props);
this.state = {selections: [], donateActive: true, fundraiseActive: false, speakActive: false };
}
componentDidMount() {
this.setState({
selections: selectionData.selections
})
}
componentWillUnMount(){
console.log("unmounted!");
}
donateOnClick() {
this.setState({ donateActive: true, fundraiseActive: false, speakActive: false});
}
fundraiseOnClick() {
this.setState({ fundraiseActive: true, donateActive: false, speakActive: false});
}
speakOnClick() {
this.setState({ speakActive: true, fundraiseActive: false, donateActive: false});
}
donateTemplate() {
return (
<div>
<h1>donate template</h1>
</div>
)
}
fundraiseTemplate() {
return (
<div>
<h1>fundraise template</h1>
</div>
)
}
speakTemplate() {
return (
<div>
<h1>speak template</h1>
</div>
)
}
render() {
return(
<div>
<div className="col-sm-6 col-sm-push-6 right">
<div className="right-content-container">
<div className="selections">
<h3>You can</h3>
<h1 onClick={this.donateOnClick} className="selection active" id="selection-donate">donate</h1>
<h1 onClick={this.fundraiseOnClick} className="selection" id="selection-fundraise">fundraise</h1>
<h1 onClick={this.speakOnClick} className="selection" id="selection-speak">speak up</h1>
<hr></hr>
</div>
<div>
{
if (this.state.donateActive) {
this.donateTemplate()
}
if (this.state.fundraiseActive) {
this.fundraiseTemplate()
}
if (this.state.speakActive) {
this.speakTemplate()
}
}
</div>
</div>
</div>
<div className="col-sm-6 col-sm-pull-6 left">
<div className="left-content-container">
<img className="img-responsive hidden-xs" src="./images/selections/.jpg" alt=""/>
<img className="img-responsive hidden-sm hidden-md hidden-lg" src="./images/selections/.jpg" alt=""/>
</div>
</div>
</div>
);
}
}
を、私は内部の今return()
の内側に私がやっている方法をIF
ステートメントを使用することができていますかどうかわからないんだけどrender()
メソッドは、これを行うための良い方法はありますか?
ご協力いただければ幸いです。
可能な重複[リアクトアクセスできません。インスタンス(this)内部のイベントハンドラ](http://stackoverflow.com/questions/29577977/unable-to-access-react-instance-this-inside-event-handler) –