Skip to content

Instantly share code, notes, and snippets.

@coderek
Last active September 22, 2020 03:20
Show Gist options
  • Save coderek/db2b956fb72c0301a4882a8739f2595a to your computer and use it in GitHub Desktop.
Save coderek/db2b956fb72c0301a4882a8739f2595a to your computer and use it in GitHub Desktop.
React Components, Elements, and Instances

Element

An element is a plain object describing a component instance or DOM node and its desired properties

It contains only information about the component type (for example, a Button), its properties (for example, its color), and any child elements inside it.

An element is not an actual instance. Rather, it is a way to tell React what you want to see on the screen. You can’t call any methods on the element. It’s just an immutable description object with two fields: type: (string | ReactClass) and props: Object1.

DOM Element

{
  type: 'button',
  props: {
    className: 'button button-blue',
    children: {
      type: 'b',
      props: {
        children: 'OK!'
      }
    }
  }
}

Component Element

{
  type: Button,
  props: {
    color: 'blue',
    children: 'OK!'
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment