Welcome to the Arcane Academy! You've just arrived at the grand Enrollment Hall, clutching your acceptance letter. Before you can begin your magical training, you must register yourself in the Academy's ancient systems using the React.createElement() incantation — the original spell for creating React elements.
By the end of this module, you will:
- Understand how React creates elements using JavaScript
- Work with JavaScript objects and arrays to represent data
- Render elements to the DOM using ReactDOM
- Create nested element structures
- Write functions that calculate values
React.createElement()ReactDOM.render()/ReactDOM.createRoot()- Element properties and children
- Rendering lists of elements
- Basic component structure
- Objects and object properties
- Arrays and array iteration
- Functions and return values
- Template strings (for concatenation)
- DOM manipulation basics
Start with the introduction slides before the demos:
- Navigate to the
slides/folder - Run
npm installthennpm run dev - Open http://localhost:5173
- Use arrow keys or buttons to navigate
The slides cover:
- What is React?
- Why learn React?
- Course structure and resources
- What to expect in Module 1
This module uses React from a CDN, so no build tools are required!
- Navigate to the
demo/folder - Open
index.htmlin your web browser - Open the browser's developer console to see any output
- Study the code in both
index.htmlandapp.js
The demo (demo/app.js) shows:
- Creating a student object with properties like name, house, and magicLevel
- Using React.createElement() to create React elements representing the student
- Rendering to the DOM using ReactDOM
Key points to notice:
React.createElement(type, props, ...children)creates a React element- The first argument is the HTML tag (string) or component
- The second argument is an object of properties/attributes
- Remaining arguments are the children (text or more elements)
- We use
ReactDOM.createRoot()androot.render()in React 18
Difficulty: Beginner
Create a student object with your wizard's stats and render it using createElement().
Difficulty: Beginner-Intermediate
Build an array of multiple students and render them as a list using .map().
Once you've completed both quests, try this:
The Student Comparison Tool
Create a small application that:
- Has TWO student objects with different stats
- Calculates and displays which student is more powerful
- Shows a comparison of their stats side-by-side
- Has a button that "swaps" which student is on the left vs right
This combines object manipulation, createElement, event handling, and DOM updates!
- React elements are created with
React.createElement() - Elements are just JavaScript objects describing what should appear on screen
- We can use regular JavaScript (objects, arrays, functions) to generate React elements
createElementcan be nested to create complex structures- This is the foundation upon which JSX is built (coming in Module 2!)
Next Module: Module 2: JSX and Components — Learn the modern JSX syntax that makes React much easier to read and write!