Berk Gaffaroğlu
Berk Gaffaroğlu

Reputation: 96

Passing argument inside React.createElement()

I am trying to pass argument name in React.createElement() and I failed. And I want to use JSX only. Here is my code:

const Main = (props) => {
    return React.createElement(
    'div',
    null,
    React.createElement('h1', {props.name})
    )
}

Upvotes: 0

Views: 346

Answers (1)

Abito Prakash
Abito Prakash

Reputation: 4770

The second argument to createElement is the props we are passing to the component and third argument is the children, here props.name needs to be the child of h1 tag

React.createElement('h1', null, props.name);

You can verify this from the online babel compiler

Online babel compiler

enter image description here

Upvotes: 1

Related Questions