Skip to content
Open

done #680

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"dependencies": {
"prop-types": "^15.7.2",
"react": "^16.8.0",
"react": "^16.8.6",
"react-dom": "^16.8.0",
"react-redux": "^7.1.0",
"redux": "^4.0.1"
Expand All @@ -19,5 +19,17 @@
"build": "react-scripts build",
"eject": "react-scripts eject",
"test": "react-scripts test"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
10 changes: 9 additions & 1 deletion src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@ export const DECREMENT = 'DECREMENT';

export const increment = () => {
// Fill in this function
return {
type: INCREMENT,
payload: 1
};
};

export const decrement = () => {
// Fill in this function
};
return {
type: DECREMENT,
payload: -1
};
};
6 changes: 3 additions & 3 deletions src/components/Counter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Component } from "react";
import React, { Component } from "react";
import { connect } from 'react-redux';
import { increment, decrement } from '../actions';

Expand All @@ -20,10 +20,10 @@ class Counter extends Component {
return (
<p>
Clicked: {this.props.count} times
<button onClick={() => {/* Fill me in */ }}>
<button onClick={() => {this.props.increment() }}>
+
</button>
<button onClick={() => {/* Fill me in */ }}>
<button onClick={() => {this.props.decrement() }}>
-
</button>
{/* Uncomment these button tags if you got
Expand Down
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const store = createStore(counter);
// is passing its state to. The Provider component is also
// where the store "lives".
ReactDOM.render(
<Provider store={store}>
<Counter />
</Provider>,
document.getElementById('root')
<Provider store={store}>
<Counter />
</Provider>,
document.getElementById('root')
);
26 changes: 16 additions & 10 deletions src/reducers/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import { INCREMENT, DECREMENT } from '../actions';

const initialState = {
count: 0
}
count: 0
};

// Our reducer that handles our two action cases:
// increment and decrement. It receives the state
// of our redux store, along with an action created
// by our action creator. What does the reducer
// need to do with the count in each case?
export default (state = initialState, action) => {
switch (action.type) {
case INCREMENT:
// Fill in the body of this case
case DECREMENT:
// Fill in the body of this case
default:
return state;
}
switch (action.type) {
case INCREMENT:
// Fill in the body of this case
return {
count: state.count + action.payload
};
case DECREMENT:
// Fill in the body of this case
return {
count: state.count + action.payload
};
default:
return state;
}
};
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8131,7 +8131,7 @@ react-test-renderer@^16.8.6:
react-is "^16.8.6"
scheduler "^0.13.6"

react@^16.8.0:
react@^16.8.6:
version "16.8.6"
resolved "https://registry.yarnpkg.com/react/-/react-16.8.6.tgz#ad6c3a9614fd3a4e9ef51117f54d888da01f2bbe"
integrity sha512-pC0uMkhLaHm11ZSJULfOBqV4tIZkx87ZLvbbQYunNixAAvjnC+snJCg0XQXn9VIsttVsbZP/H/ewzgsd5fxKXw==
Expand Down