Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

React create element props is undefined

I have a generic ListComponent function

function ListComponent() {
    return React.createElement(
      "ul",
      { className: "list" },
      items.map((item, i) => React.createElement("li", {key: i}, item))
    );
  }

Now I want to pass an array to that component as props and render it:

const vacations = ["Spain", "Greece", "Vietnam"];
const VacationsList = React.createElement(ListComponent, {items: vacations}, null);

ReactDOM.render(VacationsList, document.getElementById("root"));

I am getting the ReferenceError "items is not defined". How can I fix this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You have to recieve the items like

function ListComponent({ items }) {
    return React.createElement(
      "ul",
      { className: "list" },
      items.map((item, i) => React.createElement("li", {key: i}, item))
    );
  }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading