This question may look a bit amature but i can't understand the way it works and i had to ask it here, Look at this code, it's a simple React component:
const title = React.createElement(
'h1',
{id: 'title', className: 'header'},
'Hello World'
)
ReactDOM.render(
title,
document.getElementById('react-container')
)
Now we define createElement
and render
methods as constant or somehow make a shortcut :
const { createElement } = React;
const { render } = ReactDOM;
const title = createElement(
'h1',
{id: 'title', className: 'header'},
'Hello World'
)
render(
title,
document.getElementById('react-container')
)
I can't understand how it works and how somehow relate the constant name to the React object, i would appreciate it if someone explains it to me.