File tree 2 files changed +93
-0
lines changed
2 files changed +93
-0
lines changed Original file line number Diff line number Diff line change
1
+ import * as React from "react" ;
2
+ import { connect } from "react-redux" ;
3
+
4
+ import { Store } from "common/redux/store"
5
+ import { changeTitle } from "common/redux/action"
6
+ import { Title } from "common/component/Title"
7
+ import { Button } from "common/component/Button"
8
+ import { LinkButton } from "common/component/LinkButton"
9
+
10
+ interface HomeProps {
11
+ title : string ;
12
+ updateTitle : any ;
13
+ }
14
+
15
+ class Home extends React . Component < HomeProps > {
16
+ titleList : string [ ] ;
17
+
18
+ constructor ( props : HomeProps ) {
19
+ super ( props ) ;
20
+
21
+ this . titleList = [
22
+ "Hello World!" ,
23
+ "High five from React" ,
24
+ "Wow. Much skills."
25
+ ] ;
26
+
27
+ this . setRandomTitle = this . setRandomTitle . bind ( this ) ;
28
+ }
29
+
30
+ public setRandomTitle ( ) {
31
+ let titleIndex = this . titleList . indexOf ( this . props . title ) + 1 ;
32
+ if ( titleIndex >= this . titleList . length ) {
33
+ titleIndex = 0 ;
34
+ }
35
+
36
+ const newTitle = this . titleList [ titleIndex ] ;
37
+ this . props . updateTitle ( newTitle ) ;
38
+ }
39
+
40
+ public render ( ) {
41
+ return (
42
+ < div className = "Home" >
43
+ < Title >
44
+ { this . props . title }
45
+ </ Title >
46
+ < Button onClick = { this . setRandomTitle } >
47
+ Update
48
+ </ Button >
49
+ < LinkButton to = "/test" >
50
+ Go to test
51
+ </ LinkButton >
52
+ </ div >
53
+ ) ;
54
+ }
55
+ }
56
+
57
+ const mapStateToProps = ( state : Store ) => {
58
+ return {
59
+ title : state . title
60
+ }
61
+ }
62
+
63
+ const mapDispatchToProps = {
64
+ updateTitle : changeTitle
65
+ }
66
+
67
+ export default connect ( mapStateToProps , mapDispatchToProps ) ( Home )
Original file line number Diff line number Diff line change
1
+ import * as React from "react" ;
2
+
3
+ import { Title } from "common/component/Title" ;
4
+ import { Button } from "common/component/Button" ;
5
+ import { LinkButton } from "common/component/LinkButton" ;
6
+
7
+ export default class Test extends React . Component {
8
+ public render ( ) {
9
+ return (
10
+ < div className = "Test" >
11
+ < Title >
12
+ This is the test container
13
+ </ Title >
14
+ < Title >
15
+ Yes it is
16
+ </ Title >
17
+ < Button primary >
18
+ Here is a useless primary button
19
+ </ Button >
20
+ < LinkButton to = "/" >
21
+ Go back
22
+ </ LinkButton >
23
+ </ div >
24
+ ) ;
25
+ }
26
+ }
You can’t perform that action at this time.
0 commit comments