0

I'm learning React and I thought that React.createElement(type, [props], [...children]) was just a method that encapsulates the DOM methods.

So, I thought that this React example: React.createElement('h1', {className: 'greeting'}, 'Hello, world!') would execute something like these statements:

const element = document.createElement('h1');
element.setAttribute('class', 'greeting');
document.createTextNode('Hello World');

However, I just read in their documentation that this method returns this object:

// Note: this structure is simplified
const element = {
  type: 'h1',
  props: {
    className: 'greeting',
    children: 'Hello, world!'
  }
};

Does anyone have more information about why it creates an object, and how does it communicate with the HTML?

1 Answer 1

1

You can read about reconciliation, read the Fiber architecture guide, and view the React DOM source for a very comprehensive understanding.

Essentially, React DOM acts as a mediator to reconcile the state of the DOM with those objects.

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.