We instantiate React elements using the
React.createElement API. Typically, we call this API using JSX elements, but it's also possible to call it directly.
The function signature is:
createElement(type, props, children).
Let's take a quick peek at the internals of a React element tree. The exact details of the element tree aren't important to understand right now, but it's useful to get the gist of how React works.
In this example, we instantiate a few React components using JSX and then print their value to the console.
typeis a function representing what UI element to render.
propsobject may contain arbitrary properties, e.g.
foo, plus a
childrenproperty containing nested React elements. The
childrenproperty is somewhat special, since it's created automatically from the nested JSX elements in our code.
key aren't props... we'll come back to those.
Want to learn React Native in-depth?