Skip to content

Commit 676640a

Browse files
author
Sven
committed
refactor: propType locations
1 parent d9a09be commit 676640a

File tree

6 files changed

+45
-34
lines changed

6 files changed

+45
-34
lines changed

src/components/Loading.jsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ import React from 'react'
22
import { bool } from 'prop-types'
33
import Spinner from 'react-spinkit'
44

5+
const propTypes = {
6+
isLoading: bool,
7+
timedOut: bool,
8+
pastDelay: bool,
9+
error: bool
10+
}
511
function Loading(props) {
612
if (props.isLoading) {
713
// While our other component is loading...
@@ -24,11 +30,6 @@ function Loading(props) {
2430
}
2531
}
2632

27-
Loading.propTypes = {
28-
isLoading: bool,
29-
timedOut: bool,
30-
pastDelay: bool,
31-
error: bool
32-
}
33+
Loading.propTypes = propTypes
3334

3435
export default Loading

src/components/PrivateRoute.jsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import PropTypes from 'prop-types'
33
import { Route, Redirect } from 'react-router-dom'
44
import { connect } from 'react-redux'
55

6+
const propTypes = {
7+
isAuthenticated: PropTypes.bool.isRequired,
8+
component: PropTypes.func.isRequired,
9+
location: PropTypes.object.isRequired,
10+
}
11+
612
function PrivateRoute({ component: Component, isAuthenticated, ...rest }) {
713
return (
814
<Route {...rest} render={props => (
@@ -21,11 +27,7 @@ function PrivateRoute({ component: Component, isAuthenticated, ...rest }) {
2127
)
2228
}
2329

24-
PrivateRoute.propTypes = {
25-
isAuthenticated: PropTypes.bool.isRequired,
26-
component: PropTypes.func.isRequired,
27-
location: PropTypes.object.isRequired,
28-
}
30+
PrivateRoute.propTypes = propTypes
2931

3032
const mapStateToProps = (state) => ({
3133
isAuthenticated: state.isAuthenticated

src/routes/Counter/components/Counter.jsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ import { Button } from 'reactstrap'
44

55
// Stateless Functional Component
66
// React style:https://github.com/airbnb/javascript/tree/master/react
7+
const propTypes = {
8+
counter: number.isRequired,
9+
increment: func.isRequired,
10+
doubleAsync: func.isRequired
11+
}
12+
713
function Counter({ counter, increment, doubleAsync }) {
814
return (<div style={{ margin: '0 auto' }}>
915
<h3>Counter: {counter}</h3>
@@ -17,10 +23,6 @@ function Counter({ counter, increment, doubleAsync }) {
1723
</div>)
1824
}
1925

20-
Counter.propTypes = {
21-
counter: number.isRequired,
22-
increment: func.isRequired,
23-
doubleAsync: func.isRequired
24-
}
26+
Counter.propTypes = propTypes
2527

2628
export default Counter

src/routes/Login/components/Login.jsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ import PropTypes from 'prop-types'
33
import { Redirect } from 'react-router-dom'
44
import { Button, Container } from 'reactstrap'
55

6+
const propTypes = {
7+
authenticateWithCb: PropTypes.func.isRequired,
8+
location: PropTypes.shape({
9+
state: PropTypes.object,
10+
}).isRequired,
11+
isAuthenticated: PropTypes.bool.isRequired,
12+
}
13+
614
function Login({ location, isAuthenticated, authenticateWithCb }) {
715
const { from } = location.state || { from: { pathname: '/' } }
816
return isAuthenticated ? <Redirect to={from} />
@@ -13,12 +21,6 @@ function Login({ location, isAuthenticated, authenticateWithCb }) {
1321
</Container>
1422
)
1523
}
16-
Login.propTypes = {
17-
authenticateWithCb: PropTypes.func.isRequired,
18-
location: PropTypes.shape({
19-
state: PropTypes.object,
20-
}).isRequired,
21-
isAuthenticated: PropTypes.bool.isRequired,
22-
}
24+
Login.propTypes = propTypes
2325

2426
export default Login

src/routes/PageNotFound/components/PageNotFound.jsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import './PageNotFound.scss'
55
import { withRouter } from 'react-router'
66
import { Button } from 'reactstrap'
77

8+
const propTypes = {
9+
history: object.isRequired,
10+
}
11+
812
function PageNotFound({ history: { goBack } }) {
913
return (<div className="not-found__container">
1014
<p>Page not found!!!</p>
@@ -24,8 +28,6 @@ function PageNotFound({ history: { goBack } }) {
2428
</div>)
2529
}
2630

27-
PageNotFound.propTypes = {
28-
history: object.isRequired,
29-
}
31+
PageNotFound.propTypes = propTypes
3032

3133
export default withRouter(PageNotFound)

src/routes/Zen/components/Zen.jsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ import PropTypes from 'prop-types'
33
import Spinner from 'react-spinkit'
44
import { Button } from 'reactstrap'
55

6+
const propTypes = {
7+
fetchZen: PropTypes.func.isRequired,
8+
clearZen: PropTypes.func.isRequired,
9+
zen: PropTypes.shape({
10+
fetching: PropTypes.bool.isRequired,
11+
text: PropTypes.array,
12+
}).isRequired,
13+
}
14+
615
function Zen({ fetchZen, clearZen, zen: { fetching, text } }) {
716
return (
817
<div>
@@ -23,13 +32,6 @@ function Zen({ fetchZen, clearZen, zen: { fetching, text } }) {
2332
</div>)
2433
}
2534

26-
Zen.propTypes = {
27-
fetchZen: PropTypes.func.isRequired,
28-
clearZen: PropTypes.func.isRequired,
29-
zen: PropTypes.shape({
30-
fetching: PropTypes.bool.isRequired,
31-
text: PropTypes.array,
32-
}).isRequired,
33-
}
35+
Zen.propTypes = propTypes
3436

3537
export default Zen

0 commit comments

Comments
 (0)