P
P
Pantene7422018-07-15 00:52:12
Node.js
Pantene742, 2018-07-15 00:52:12

How does the render() method work in React?

As far as I know, passing a parameter of this type is not supported in JS. return returns parenthesized html code and not in quotes, and not in ` ` as a string.
Before building, the React compiler parses the data in the component files (namely, those that the render function returns) and translates them into a working form for ES6, or is it normal for ES6. (I understand that react builds everything in ES2015 )

render() {
    return (
      <Row className="show-grid">
        <Col md={6}>
          <h2>Est. total</h2>
        </Col>
        <Col md={6}>
          <h2>{`$${this.props.price}`}</h2>
        </Col>
      </Row>
    );
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2018-07-15
@Pantene742

return returns parenthesized html code

return does not return html code. JSX is just syntactic sugar on top of JavaScript .
jsx like:
render() {
  return (
    <h1 className="greeting">
      Hello, world!
    </h1>
  );
}

is translated into JS of the form:
render() {
  return React.createElement(
    'h1',
    { className: 'greeting' },
    'Hello, world!'
  );
}

the result of executing render in this case will be the following:
{
  $$typeof: Symbol(react.element),
  key: null,
  props: { className: "greeting", children: "Hello, world!" },
  ref: null,
  type: "h1",
  _owner: null,
  _store: { validated: false },
  _self: null,
  _source: null,
  __proto__: Object,
}

The returned object is a Virtual DOM Node . According to it, the library creates an element in the real DOM .
React compiler parses data in component files before building...
...I understand that React builds everything in ES2015...
No. JSX is not part of the ECMAScript 2015 specification

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question