2

For instance, this code snippet:

React.createElement(
  "h1",
  null,
  "Shopping List for ",
  props.name
),

What does the null value represent, or what can it be used for?

2
  • 1
    Not sure why you got the downvote (maybe because use of createElement() is discouraged in favor of JSX). Anyway, the second argument is an object containing properties ('props' in React terms) that get passed to the component. From here: learn.co/lessons/react-create-element Commented Dec 9, 2018 at 19:01
  • 1
    "This question does not show any research effort" – the answer is in the official documentation and API. Commented Dec 9, 2018 at 19:31

1 Answer 1

7

From the React docs:

createElement()

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

Create and return a new React element of the given type. The type argument can be either a tag name string (such as 'div' or 'span'), a React component type (a class or a function), or a React fragment type.

What the docs don’t explicitly mention is that props should be an object. For example:

{
  click: dothing,
  className: 'myClass'
}

It may be {} or null if you need to specify children but not properties

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.