File tree 2 files changed +45
-0
lines changed
2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ function customRender ( reactElement , container ) {
2
+ // this is not best way beacuse every time use to setAttribute for every element
3
+
4
+ // const domElement = document.createElement(reactElement.type);
5
+ // domElement.innerHTML = reactElement.children;
6
+ // domElement.setAttribute("href", reactElement.props.herf);
7
+ // domElement.setAttribute("target", reactElement.children.target);
8
+ // container.appendChild(domElement);
9
+
10
+ // loop base code , best way
11
+
12
+ const domElement = document . createElement ( reactElement . type ) ;
13
+ domElement . innerHTML = reactElement . children ;
14
+ for ( const prop in reactElement . props ) {
15
+ if ( prop == "children" ) continue ; // if prop attr have h children element
16
+ domElement . setAttribute ( prop , reactElement . props [ prop ] ) ;
17
+ }
18
+ container . appendChild ( domElement ) ;
19
+ }
20
+
21
+ const reactElement = {
22
+ type : "a" ,
23
+ props : {
24
+ herf : "https://google.com" ,
25
+ target : "_blank" ,
26
+ } ,
27
+ children : "Visit Google" ,
28
+ } ; // react give same like this end of the day
29
+
30
+ const mainContainer = document . querySelector ( "#root" ) ;
31
+
32
+ customRender ( reactElement , mainContainer ) ;
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 " />
5
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
6
+ < title > Custom React App</ title >
7
+ </ head >
8
+ < body >
9
+ < div id ="root "> </ div >
10
+
11
+ < script src ="./custom-react.js "> </ script >
12
+ </ body >
13
+ </ html >
You can’t perform that action at this time.
0 commit comments