UPDATE: I am very new to React(and js) and playing around with it. What I want to do is that you can only click on the image every 10 secs or something. How do I do it? I am not sure where to reset isClickable.
I have something like this:
Var ClickableImage = React.createClass({ getInitialState: function(){ return { isClickable: false, counter: 0 }; }, componentDidMount: function(){ // componentDidMount is called by react when the component // has been rendered on the page. We can set the interval here: setTimeout(() => { this.setState({ isClickable: true, }); }, 1000); }, handleClick: function() { this.setState({ counter: this.state.counter+1 }); }, render: function(){ var imgStyle = { width: '80%', height: '80%', backgroundColor: "#4ECDC4" }; var counterStyle = { width: '80%', height: '80%', backgroundColor: "#674172" }; const optionalOnClick = this.state.isClickable ? { onClick: this.handleClick, isClickable: false } : {}; return( <div> <div style = {imgStyle}> <img src={this.props.src} width="100%" height="80%" onClick={this.optionalOnClick}/> </div> <div style = {counterStyle}> {this.state.counter} </div> </div> ) } });
ReactDOM.render(<ClickableImage src='http://vignette1.wikia.nocookie.net/parody/images/2/27/Minions_bob_and_his_teddy_bear_2.jpg/revision/latest?cb=20150507162409' />, document.getElementById('app'));
{...optionalOnClick}- it expands the object to the component properties 2.optionalOnClickshould not have anything butonClick3. After you do that you'll likely to have a problem withthisin the click handler