0

Something wrong error occured!

I use react js and react-rails gem.

I have a problem. When I add a onClick attribute to JSX onClick={() => this.handleClick()}, but it does not work.

If I removed a onClick attribute, It works. Why??

export default class Popup extends React.Component{
  constructor(props){
    super(props)
  }
  componentWillMount(){
    this.setState({
      show: true
    })
  }
  handleClick(){
    console.log('name')
  }
  render(){
    return(
      <div className={`c-popup c-popup--white ${this.state.show ? 'is-active' : ''}`}>
        <article className="c-popup__box">
          <button onClick={() => console.log('aiueo')} className="c-popup__box-close"> //Here!!!!!!! It's not working!
            <i className="icon ion-close"></i>
          </button>
        </article>
      </div>
    )
  }
}

export default class Popup extends React.Component{
  constructor(props){
    super(props)
  }
  componentWillMount(){
    this.setState({
      show: true
    })
  }
  handleClick(){
    console.log('name')
  }
  render(){
    return(
      <div className={`c-popup c-popup--white ${this.state.show ? 'is-active' : ''}`}>
        <article className="c-popup__box">
          <button className="c-popup__box-close"> //This code is working.
            <i className="icon ion-close"></i>
          </button>
        </article>
      </div>
    )
  }
}

Thank you for your patience with my poor English!

It is error detail

minmin
  • 53
  • 1
  • 13
  • what do you mean "not working"? is it the click not working on the component breaks? If so how do you say that the second code works? – yadhu Dec 05 '16 at 06:33
  • @free-soul Thank you! I pasted error detail. Please check it! – minmin Dec 05 '16 at 07:13
  • are you not getting this error with the second code? – yadhu Dec 05 '16 at 07:17
  • I got this error sometime. Almost cause of errors is javascript syntax error. So, everytime when this error occued, I check javascript code and find wrong syntax and fixed. But now I cannot find wrong syntax. – minmin Dec 05 '16 at 07:27
  • @free-soul Sorry, React.Component in other file has wrong syntax!!!! :-( :-( – minmin Dec 05 '16 at 07:33

0 Answers0