Skip to content

Commit 0d1fa6c

Browse files
author
Thomas Roger Lux
committed
Refactor existing components for containers and react router
1 parent 9848ac9 commit 0d1fa6c

File tree

3 files changed

+13
-56
lines changed

3 files changed

+13
-56
lines changed

Diff for: src/common/App.tsx

+10-53
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,18 @@
11
import * as React from "react";
2-
import { connect } from "react-redux";
2+
import { Switch, Route } from "react-router-dom";
33

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-
9-
interface AppProps {
10-
title: string;
11-
updateTitle: any;
12-
}
13-
14-
class App extends React.Component<AppProps> {
15-
titleList: string[] = [
16-
"Hello World!",
17-
"High five from React",
18-
"Wow. Much skills."
19-
];
20-
21-
constructor(props: AppProps) {
22-
super(props);
23-
24-
this.setRandomTitle= this.setRandomTitle.bind(this);
25-
}
26-
27-
public setRandomTitle() {
28-
let titleIndex = this.titleList.indexOf(this.props.title) + 1;
29-
if (titleIndex >= this.titleList.length) {
30-
titleIndex = 0;
31-
}
32-
33-
const newTitle = this.titleList[titleIndex];
34-
this.props.updateTitle(newTitle);
35-
}
4+
import Home from "common/container/Home";
5+
import Test from "common/container/Test";
366

7+
export default class App extends React.Component {
378
public render() {
389
return (
39-
<div className="App">
40-
<Title>
41-
{this.props.title}
42-
</Title>
43-
<Button onClick={this.setRandomTitle}>
44-
Update
45-
</Button>
46-
</div>
10+
<main>
11+
<Switch>
12+
<Route exact path="/" component={Home} />
13+
<Route path="/test" component={Test} />
14+
</Switch>
15+
</main>
4716
);
4817
}
4918
}
50-
51-
const mapStateToProps = (state: Store) => {
52-
return {
53-
title: state.title
54-
}
55-
}
56-
57-
const mapDispatchToProps = {
58-
updateTitle: changeTitle
59-
}
60-
61-
export default connect(mapStateToProps, mapDispatchToProps)(App)

Diff for: src/common/component/Button.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import * as React from "react";
22
import styled, { css } from "styled-components";
33

44
interface ButtonProps {
5-
onClick: any;
6-
children: string;
5+
children?: any;
6+
onClick?: any;
77
primary?: boolean;
88
}
99

Diff for: src/common/component/Title.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from "react";
22
import styled from "styled-components";
33

44
interface TitleProps {
5-
children: string;
5+
children?: any;
66
}
77

88
export const Title = (props: TitleProps) => {

0 commit comments

Comments
 (0)