Y
Y
yuriytkachenko2019-08-31 19:36:37
React
yuriytkachenko, 2019-08-31 19:36:37

What do they write in brackets {} in the render function in react?

The documentation explains why they write code in the render function between { } rather superficially. It says that the { } code is written in curly braces so that JSX understands that this is JavaScript. Or they write that you can write a JS expression in brackets. But expressions in my understanding are something like this: a= b+c or a=b.
And I often see that in curly brackets they write just one word and that's it. Here are some examples:

render() {
 
    return (
     <WeatherDisplay
          key={activePlace}                      // ВОТ ЗДЕСЬ
          zip={PLACES[activePlace].zip}  //ИЛИ ЗДЕСЬ 
        />
      </div>
    );
}

render() {
    const { isActive } = this.state;              // И ЕЩЕ

    return (
      <div>
        <button onClick={handleClick}>Try it</button>    // И ВОТ
        <div className={isActive ? 'mystyle' : ''}>    
          This is a DIV element.
        </div>
      </div>
    );
  }
}

So what do they write between the curly braces?
What are your options for writing there?
Are these the result values ​​of the calculations in the function?
Are they object references?
Are these references to variables that we have manipulated and have now assigned a new value to some element?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
i1yas, 2019-08-31
@yuriytkachenko

in my understanding it is something like this: a= b+c or a=b.

An expression is any construct that evaluates to a value. One variable written just like that is also an expression:
const a = 1;
a; // это выражение

Actually, by default, react props accept strings, if you need to pass something else, then you need to use curly braces, even if it's a number.

0
0xD34F, 2019-08-31
@0xD34F

But expressions in my understanding are...

Clear.
Forget about react for the next six months and go learn js.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question