0

I need a modal to open with onClick, the variable calling the modal is nested between Translation keys. Here's some of the code. When clicking the link text, I currently have this error message: Cannot read property 'modaleNouvelleOeuvre' of undefined :-/

modaleNouvelleOeuvre(ouvert = true) { /*Ouvert means Open*/
this.setState({ modaleOeuvre: ouvert })
}
{t('flot.split.tableaudebord.vide.indication')}
<a href="#" onClick={(e) => { e.preventDefault(); this.modaleNouvelleOeuvre() }}>
{t('flot.split.tableaudebord.vide.indication-lien')}</a>

There's a button elsewhere on the page to open the same modal:

<Modal
open={this.state.modaleOeuvre}
onClose={() => { this.modaleNouvelleOeuvre(false); if (this.state.audio) this.state.audio.stop() }}
size="large"
closeIcon
closeOnDimmerClick={false}
>
2
  • Can you add more code or code sandbox link? It's hard to tell from this? Commented Oct 25, 2019 at 19:54
  • Not sure what would be useful in this case but I added some Commented Oct 25, 2019 at 20:18

1 Answer 1

1

That's because you're invoking this.modaleNouvelleOeuvre() inside the <a>.

<a href="#" onClick={this.modaleNouvelleOeuvre}>

modaleNouvelleOeuvre(e) {  
  e.preventDefault()
  this.setState({ modaleOeuvre: !this.state.ouvert })
}

Note: e or event is implicit.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.