File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,4 +2,24 @@ import React from 'react'; // 虽然也许可能没有使用,如果删了就
22import ReactDOM from 'react-dom' ;
33
44// import './test/test1'
5- import './test/toggleImg'
5+ // import './test/toggleImg'
6+
7+ import FuncComp from './test/Comp/func'
8+ import ClassComp from './test/Comp/class' ;
9+ const el = ( < FuncComp str = "ceilf6" num = { 7 } > </ FuncComp > )
10+ console . log ( el )
11+ // 组件生成的仍然是React元素,但是 type: ƒ Comp()
12+ // 如果首字母不大写的话就是普通元素
13+ const el2 = ( < ClassComp str = "ceilf6" num = { 7 } > </ ClassComp > ) // type: class ClassComp
14+ console . log ( el2 )
15+ const allEl = (
16+ < >
17+ { el }
18+ { el2 }
19+ { < FuncComp useless = { false } useful
20+ obj = { { name : "ceilf6" , age : 20 , ui : ( < div > nihao</ div > ) } }
21+ >
22+ </ FuncComp > }
23+ </ >
24+ )
25+ ReactDOM . render ( allEl , document . getElementById ( 'root' ) )
Original file line number Diff line number Diff line change 1+ import React from 'react'
2+
3+ export default class ClassComp extends React . Component {
4+ constructor ( props ) {
5+ super ( props ) ; // this.props = props
6+ console . log ( "=== props" , props )
7+ }
8+
9+ render ( ) {
10+ return (
11+ < h1 > nihao2 { this . props . num } </ h1 >
12+ )
13+ }
14+ }
Original file line number Diff line number Diff line change 1+ // imr
2+ import React from 'react'
3+
4+ export default function FuncComp ( props ) {
5+ console . log ( "=== props" , props )
6+ /**
7+ * 危险!!否则排查很麻烦
8+ */
9+ // if(props?.obj?.name) props.obj.name = "250"
10+ // props.obj = {name: "250"}
11+ // error: readonly
12+ return (
13+ < >
14+ < h1 > nihao { props . str } { props . num } </ h1 >
15+ < h1 > objName: { props ?. obj ?. name } </ h1 >
16+ < h1 > objUI: { props ?. obj ?. ui } </ h1 >
17+ </ >
18+ )
19+ }
You can’t perform that action at this time.
0 commit comments