I am in the process of learning React and was stuck at once place. To make things clear, I am first trying to use React without any JSX. All I am loading is the React and React DOM library. I defined a component like this:
function Weekday(props) {
return React.createElement('p', null, `Today is ${props.day}`);
}
let dayElem = React.createElement(Weekday, {day: 'Monday'});
ReactDOM.createRoot(document.getElementById('app')).render(dayElem);
My question is why do I need to call createElement
twice? The function Weekday
is already returning a React element. So, what did I have to call createElement another time while passing it the function name Wednesday
. Why couldn’t dayElem simply be like this:
let dayElem = Weekday({day: 'Monday'});