Skip to content

Commit cdcfe21

Browse files
authored
Update README.md
1 parent 2422129 commit cdcfe21

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,31 @@ Now let's get back to where we were, hooks!
5757
<i><b>Note: This is an oversimplified version of what happens under the hood, React doesn't use this to power their library.
5858
</b></i>
5959

60+
```
61+
let React = (function() {
62+
let global = {}; // define a global variable where we store information about the component
63+
let index = 0; // index to keep track of the component's state
64+
function render(Component) {
65+
global.Component = Component;
66+
const instance = Component(); // get the instance of the component
67+
index = 0;
68+
instance.render();
69+
global.instance = instance; // store the component's instance for any future calls of the component's functions
70+
return global; // return the global variable
71+
}
72+
73+
function useState(initialState) {
74+
// implement useState
75+
}
76+
77+
function useEffect(cb, deps) {
78+
// implement useEffect
79+
}
80+
81+
return { render, useState, useEffect };
82+
})();
83+
```
84+
6085
Let's break down the code once before we move forward. 
6186

6287
<b>Step 1:</b> We define a global object to keep track of the component's properties. 

0 commit comments

Comments
 (0)