```jsx file=./00.jsx
```
### Step I: The `createElement` Function
Let's start again with another app. This time we'll replace React code with our own version of React.
We'll start by writing our own `createElement`.
Let's transform the JSX to JS so we can see the `createElement` calls.
```jsx file=./01.jsx
```
As we saw in the previous step, an element is an object with `type` and `props`. The only thing that our function needs to do is create that object.
```jsx file=./02.jsx
```
We use the _spread operator_ for the `props` and the _rest parameter syntax_ for the `children`, this way the `children` prop will always be an array.
For example, `createElement("div")` returns:
```json
{
"type": "div",
"props": { "children": [] }
}
```
`createElement("div", null, a)` returns:
```json
{
"type": "div",
"props": { "children": [a] }
}
```
and `createElement("div", null, a, b)` returns:
```json
{
"type": "div",
"props": { "children": [a, b] }
}
```
```jsx file=./03.jsx
```
The `children` array could also contain primitive values like strings or numbers. So we'll wrap everything that isn't an object inside its own element and create a special type for them: `TEXT_ELEMENT`.
_React doesn't wrap primitive values or create empty arrays when there aren't `children`, but we do it because it will simplify our code, and for our library we prefer simple code than performant code._
```jsx file=./03.jsx 25,28,29,30
```
We are still using React's `createElement`.
In order to replace it, let's give a name to our library. We need a name that sounds like React but also hints its _didactic_ purpose.
```jsx file=./04.jsx
```
We'll call it Didact.
But we still want to use JSX here. How do we tell babel to use Didact's `createElement` instead of React's?
```jsx file=./05.jsx
```
If we have a comment like this one, when babel transpiles the JSX it will use the function we define.
```jsx file=./05.jsx 37
```
### Step II: The `render` Function
Next, we need to write our version of the `ReactDOM.render` function.
```jsx file=./06.jsx 25:27,29,31,32,42
```
For now, we only care about adding stuff to the DOM. We'll handle updating and deleting later.
```jsx file=./07.jsx 25:29
```
We start by creating the DOM node using the element type, and then append the new node to the container.
```jsx file=./08.jsx 25,28:30,33
```
We recursively do the same for each child.
```jsx file=./09.jsx
```
We also need to handle text elements, if the element type is `TEXT_ELEMENT` we create a text node instead of a regular node.
```jsx file=./10.jsx
```
The last thing we need to do here is assign the element props to the node.
```jsx file=./10.jsx 1:58
```
And that's it. We now have a library that can render JSX to the DOM.
Give it a try on [codesandbox](https://codesandbox.io/s/didact-2-k6rbj).
### Step III: Concurrent Mode
But... before we start adding more code we need a refactor.