@@ -2,40 +2,12 @@ import React, { useState } from "react";
2
2
import styled from "styled-components" ;
3
3
import PropTypes from "prop-types" ;
4
4
import { Radio , Button } from "antd" ;
5
- import { CSSTransition } from "react-transition-group" ;
5
+ // import { CSSTransition } from "react-transition-group";
6
6
7
7
const StyledDiv = styled . div `
8
8
width: 500px;
9
9
height: 300px;
10
10
text-align: center;
11
- .line {
12
- height: 50px;
13
- line-height: 50px;
14
- }
15
- .line-height button {
16
- background-color: black;
17
- color: #fff;
18
- }
19
- .fade-enter {
20
- opacity: 0;
21
- }
22
- .fade-enter-active {
23
- opacity: 1;
24
- transition: opacity 2000ms;
25
- }
26
- .fade-enter-done {
27
- opacity: 1;
28
- }
29
- .fade-exit {
30
- opacity: 1;
31
- }
32
- .fade-exit-active {
33
- opacity: 0;
34
- transition: opacity 2000ms;
35
- }
36
- .fade-exit-done {
37
- opacity: 0;
38
- }
39
11
` ;
40
12
function Page ( ) {
41
13
const [ color , setColor ] = useState ( "blue" ) ;
@@ -50,23 +22,16 @@ function Page() {
50
22
51
23
return (
52
24
< StyledDiv >
53
- < h4 > 若父组件选择了blue按钮,子组件则不重复render</ h4 >
25
+ < h2 > 若父组件选择了yellow按钮,子组件则不重复render,可打开控制台查看console</ h2 >
26
+ < h3 >
27
+ 这个过程是在子组件里做的处理,也可以在父组件里setValue的时候,如果Value等于yellow就return,也可以达到这种效果
28
+ </ h3 >
54
29
< Radio . Group value = { color } onChange = { changeTab } >
55
30
< Radio . Button value = "blue" > blue</ Radio . Button >
56
31
< Radio . Button value = "red" > red</ Radio . Button >
57
32
< Radio . Button value = "yellow" > yellow</ Radio . Button >
58
33
</ Radio . Group >
59
- < Button style = { { marginLeft : 40 } } type = "primary" onClick = { ( ) => setShow ( ! show ) } >
60
- toggleShow
61
- </ Button >
62
- < CSSTransition
63
- in = { show } // 用于判断是否出现的状态
64
- timeout = { 800 } // 动画持续时间
65
- classNames = "fade" // className值,防止重复
66
- unmountOnExit
67
- >
68
- < Son color = { color } />
69
- </ CSSTransition >
34
+ < Son color = { color } />
70
35
</ StyledDiv >
71
36
) ;
72
37
}
@@ -88,7 +53,7 @@ class Son extends React.Component {
88
53
}
89
54
}
90
55
Son . propTypes = {
91
- color : PropTypes . string . isRequired
56
+ color : PropTypes . string . isRequired ,
92
57
} ;
93
58
94
59
export default Page ;
0 commit comments