Why we need to pass “null” as a 2nd argument to React.createElement()

Hey there, why we need to pass “null” as a 2nd argument to React.createElement()?

The React docs linked in the CC lesson explain what arguments createElement() expects:

React.createElement(
  type,
  [props],
  [...children]
)

The second argument expects props. If you don’t want to pass any props but children (the text node “Hello, world”) you need to pass null as a second argument. Otherwise the third argument for children is taken as an argument for props.

1 Like