-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor existing components for containers and react router
- Loading branch information
Thomas Roger Lux
committed
Sep 26, 2018
1 parent
9848ac9
commit 0d1fa6c
Showing
3 changed files
with
13 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,18 @@ | ||
import * as React from "react"; | ||
import { connect } from "react-redux"; | ||
import { Switch, Route } from "react-router-dom"; | ||
|
||
import { Store } from "common/redux/store" | ||
import { changeTitle } from "common/redux/action" | ||
import { Title } from "common/component/Title" | ||
import { Button } from "common/component/Button" | ||
|
||
interface AppProps { | ||
title: string; | ||
updateTitle: any; | ||
} | ||
|
||
class App extends React.Component<AppProps> { | ||
titleList: string[] = [ | ||
"Hello World!", | ||
"High five from React", | ||
"Wow. Much skills." | ||
]; | ||
|
||
constructor(props: AppProps) { | ||
super(props); | ||
|
||
this.setRandomTitle= this.setRandomTitle.bind(this); | ||
} | ||
|
||
public setRandomTitle() { | ||
let titleIndex = this.titleList.indexOf(this.props.title) + 1; | ||
if (titleIndex >= this.titleList.length) { | ||
titleIndex = 0; | ||
} | ||
|
||
const newTitle = this.titleList[titleIndex]; | ||
this.props.updateTitle(newTitle); | ||
} | ||
import Home from "common/container/Home"; | ||
import Test from "common/container/Test"; | ||
|
||
export default class App extends React.Component { | ||
public render() { | ||
return ( | ||
<div className="App"> | ||
<Title> | ||
{this.props.title} | ||
</Title> | ||
<Button onClick={this.setRandomTitle}> | ||
Update | ||
</Button> | ||
</div> | ||
<main> | ||
<Switch> | ||
<Route exact path="/" component={Home} /> | ||
<Route path="/test" component={Test} /> | ||
</Switch> | ||
</main> | ||
); | ||
} | ||
} | ||
|
||
const mapStateToProps = (state: Store) => { | ||
return { | ||
title: state.title | ||
} | ||
} | ||
|
||
const mapDispatchToProps = { | ||
updateTitle: changeTitle | ||
} | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(App) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters