0

I am trying to understand a js shortand which came up to me studying React. This is it: {this.state.isModalOpen && <div className="modal onClose={this.handleClose}"> I simplified for the sake of understanding.

In the state object I have isModalOpen set to true and handleClose is a method which toggle the isModalOpen to true or false when triggered. I understand what it does but I don't understand but what would be a more declarative way to write it to understand where it comes from?

I can write the whole class if needed, but I think it is a pretty newbie question.

Thanks!

Cerbrus
  • 70,800
  • 18
  • 132
  • 147
Filippo Rivolta
  • 324
  • 4
  • 13
  • Is it the `&&` you don't understand? – Andrew Bone Jul 24 '18 at 07:59
  • 3
    Note that nothing in the code you've quoted is "ES6"-specific. `&&` is JavaScript and has behaved the same way since ~1996 (JavaScript was created in '95, but in that initial version, `&&` and `||` resulted in booleans; the current more-useful behavior was added within a year or two I believe). The `
    ` is [JSX](https://reactjs.org/docs/introducing-jsx.html), which isn't part of JavaScript at all.
    – T.J. Crowder Jul 24 '18 at 08:01
  • Thanks for your answers, what I don't understand is why if the variable is set to true the div should be returned, I don't understand the syntax, is it the corrispective of "if it's true then return"? I have never seen such use of && operator. Thanks – Filippo Rivolta Jul 24 '18 at 12:19

0 Answers0