Home > AI > Frontend > ReactJS >

createElement

Example code:

import React, {useState, useRef} from 'react';

const element = React.createElement(
  'div',
  {id: 'login-btn'},
  'Login'
)

function App() {
  return (
    element
  )
}

export default App;

React.createElement will create this object

{
  type: 'div',
  props: {
    children: 'Login',
    id: 'login-btn'
  }
}

When it renders in DOM, it will look like this

<div id='login-btn'>Login</div>

Leave a Reply