Write react code without JSX
All following snippets are equivalent
const React = require('react')
//or import React from 'react'
const element = React.createElement('div', {id: 'my-div'}, 'hello world')
const element = <div id="my-div">hello world</div>
const element = {
$$typeof: Symbol.for('react.element'),
type: 'div',
props: {
id: 'my-div',
children: 'hello world'
}
}
'div'
can be replaced with react component definition (component class or functional component).
The last method is not recommended, as react element definition can be changed in the future.
In general, <Comp {...props}>{child}</Comp>
is transpiled to
createElement(
Comp,
props,
child
)
If Comp
is HTML primary tag, it is replaced by the string value whose value is the tag name.
Source: