Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit d124cc7

Browse files
committed
refactored cra boilerplate
1 parent acbacc4 commit d124cc7

File tree

16 files changed

+287
-251
lines changed

16 files changed

+287
-251
lines changed

.prettierrc

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
2-
"singleQuote": true,
3-
"semi": false,
4-
"jsxBracketSameLine": true
5-
}
2+
"jsxBracketSameLine": true,
3+
"singleQuote": false,
4+
"semi": true,
5+
"tabWidth": 4
6+
}

package.json

+17-9
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,35 @@
33
"homepage": "https://create-react-app-redux.now.sh",
44
"scripts": {
55
"deploy": "now && now alias",
6-
"start": "react-scripts start",
6+
"start": "cross-env NODE_PATH=src/ react-scripts start",
77
"now-start": "serve -s ./build",
8-
"build": "react-scripts build",
9-
"test": "react-scripts test --env=jsdom",
8+
"build": "cross-env NODE_PATH=src/ react-scripts build",
9+
"test": "cross-env NODE_PATH=src/ react-scripts test --env=jsdom",
1010
"eject": "react-scripts eject",
1111
"precommit": "pretty-quick --staged"
1212
},
1313
"devDependencies": {
14-
"prettier": "1.18.2",
15-
"react-scripts": "2.1.8"
14+
"prettier": "1.18.2"
1615
},
1716
"dependencies": {
1817
"connected-react-router": "4.5.0",
18+
"cross-env": "^5.2.0",
1919
"react": "16.8.6",
2020
"react-dom": "16.8.6",
2121
"react-redux": "5.1.1",
22-
"react-router": "4.4.0-beta.8",
23-
"react-router-dom": "4.4.0-beta.8",
24-
"redux": "4.0.4",
22+
"react-router": "5.0.1",
23+
"react-router-dom": "5.0.1",
24+
"react-scripts": "^3.0.1",
25+
"redux": "4.0.1",
26+
"redux-logger": "^3.0.6",
2527
"redux-thunk": "2.3.0",
2628
"sanitize.css": "7.0.3",
2729
"serve": "10.1.2"
28-
}
30+
},
31+
"browserslist": [
32+
">0.2%",
33+
"not dead",
34+
"not ie <= 11",
35+
"not op_mini all"
36+
]
2937
}

src/App.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from "react";
2+
import { Route, Link } from "react-router-dom";
3+
import Home from "common/components/Home";
4+
import About from "common/components/About";
5+
6+
const App = () => (
7+
<div>
8+
<header>
9+
<Link to="/">Home</Link>
10+
<Link to="/about-us">About</Link>
11+
</header>
12+
13+
<main>
14+
<Route exact path="/" component={Home} />
15+
<Route exact path="/about-us" component={About} />
16+
</main>
17+
</div>
18+
);
19+
20+
export default App;

src/common/components/About.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from "react";
2+
3+
const About = () => (
4+
<div>
5+
<h1>About Page</h1>
6+
<p>Did you get here via Redux?</p>
7+
</div>
8+
);
9+
10+
export default About;

src/common/components/Home.js

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import React from "react";
2+
import { push } from "connected-react-router";
3+
import { connect } from "react-redux";
4+
import {
5+
increment,
6+
incrementAsync,
7+
decrement,
8+
decrementAsync
9+
} from "counter/state/counterActions";
10+
11+
const Home = props => {
12+
const {
13+
changePage,
14+
count,
15+
decrement,
16+
decrementAsync,
17+
increment,
18+
incrementAsync,
19+
isDecrementing,
20+
isIncrementing
21+
} = props;
22+
return (
23+
<div>
24+
<h1>Home</h1>
25+
<p>Count: {count}</p>
26+
27+
<p>
28+
<button onClick={increment}>Increment</button>
29+
<button onClick={incrementAsync} disabled={isIncrementing}>
30+
Increment Async
31+
</button>
32+
</p>
33+
34+
<p>
35+
<button onClick={decrement}>Decrement</button>
36+
<button onClick={decrementAsync} disabled={isDecrementing}>
37+
Decrement Async
38+
</button>
39+
</p>
40+
41+
<p>
42+
<button onClick={changePage}>Go to about page via redux</button>
43+
</p>
44+
</div>
45+
);
46+
};
47+
48+
const mapStateToProps = ({
49+
counter: { count, isDecrementing, isIncrementing }
50+
}) => ({
51+
count: count,
52+
isDecrementing: isDecrementing,
53+
isIncrementing: isIncrementing
54+
});
55+
56+
const mapDispatchToProps = dispatch => {
57+
return {
58+
changePage: () => {
59+
dispatch(push("/about-us"));
60+
},
61+
decrement: () => {
62+
dispatch(decrement());
63+
},
64+
decrementAsync: () => {
65+
dispatch(decrementAsync());
66+
},
67+
increment: () => {
68+
dispatch(increment());
69+
},
70+
incrementAsync: () => {
71+
dispatch(incrementAsync());
72+
}
73+
};
74+
};
75+
76+
export default connect(
77+
mapStateToProps,
78+
mapDispatchToProps
79+
)(Home);

src/containers/about/index.js

-10
This file was deleted.

src/containers/app/index.js

-20
This file was deleted.

src/containers/home/index.js

-60
This file was deleted.

src/counter/state/counterActions.js

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
export const DECREMENT = "DECREMENT";
2+
export const DECREMENT_REQUESTED = "DECREMENT_REQUESTED";
3+
export const INCREMENT = "INCREMENT";
4+
export const INCREMENT_REQUESTED = "INCREMENT_REQUESTED";
5+
6+
export const decrement = () => {
7+
return dispatch => {
8+
dispatch({
9+
type: DECREMENT_REQUESTED
10+
});
11+
12+
dispatch({
13+
type: DECREMENT
14+
});
15+
};
16+
};
17+
18+
export const decrementAsync = () => {
19+
return dispatch => {
20+
dispatch({
21+
type: DECREMENT_REQUESTED
22+
});
23+
24+
return setTimeout(() => {
25+
dispatch({
26+
type: DECREMENT
27+
});
28+
}, 3000);
29+
};
30+
};
31+
32+
export const increment = () => {
33+
return dispatch => {
34+
dispatch({
35+
type: INCREMENT_REQUESTED
36+
});
37+
38+
dispatch({
39+
type: INCREMENT
40+
});
41+
};
42+
};
43+
44+
export const incrementAsync = () => {
45+
return dispatch => {
46+
dispatch({
47+
type: INCREMENT_REQUESTED
48+
});
49+
50+
return setTimeout(() => {
51+
dispatch({
52+
type: INCREMENT
53+
});
54+
}, 3000);
55+
};
56+
};

src/counter/state/counterReducers.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import {
2+
DECREMENT,
3+
DECREMENT_REQUESTED,
4+
INCREMENT,
5+
INCREMENT_REQUESTED
6+
} from "counter/state/counterActions";
7+
8+
const initialState = {
9+
count: 0,
10+
isIncrementing: false,
11+
isDecrementing: false
12+
};
13+
14+
const counter = (state = initialState, action) => {
15+
switch (action.type) {
16+
case DECREMENT_REQUESTED:
17+
return Object.assign({}, state, {
18+
isDecrementing: true
19+
});
20+
21+
case DECREMENT:
22+
return Object.assign({}, state, {
23+
count: state.count - 1,
24+
isDecrementing: !state.isDecrementing
25+
});
26+
27+
case INCREMENT_REQUESTED:
28+
return Object.assign({}, state, {
29+
isIncrementing: true
30+
});
31+
32+
case INCREMENT:
33+
return Object.assign({}, state, {
34+
count: state.count + 1,
35+
isIncrementing: !state.isIncrementing
36+
});
37+
38+
default:
39+
return state;
40+
}
41+
};
42+
43+
export default counter;

src/index.css

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
html {
2-
font-size: 100%;
2+
font-size: 100%;
33
}
44

55
body {
6-
margin: 0;
7-
padding: 0;
8-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial,
9-
sans-serif;
10-
font-size: 1rem;
11-
line-height: 1.5;
6+
margin: 0;
7+
padding: 0;
8+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial,
9+
sans-serif;
10+
font-size: 1rem;
11+
line-height: 1.5;
1212
}
1313

1414
button:disabled {
15-
opacity: 0.5;
15+
opacity: 0.5;
1616
}

0 commit comments

Comments
 (0)