Skip to content

Commit 1ae6307

Browse files
author
unknown
committed
Deal with Create action
1 parent a11d266 commit 1ae6307

File tree

5 files changed

+40
-10
lines changed

5 files changed

+40
-10
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
Learning Vanilla-Redux and React-Redux
44

55
- Deleting To do
6-
- Detail Screen
6+
- Detail Screen
7+
- Deal with Creact Action

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6+
"@reduxjs/toolkit": "^1.4.0",
67
"@testing-library/jest-dom": "^4.2.4",
78
"@testing-library/react": "^9.3.2",
89
"@testing-library/user-event": "^7.1.2",

src/components/ToDo.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import { Link } from "react-router-dom";
66
function ToDo({ text, onBtnClick, id }) {
77
return (
88
<li>
9-
<Link to={`/${id}`}>
10-
{text} <button onClick={onBtnClick}>DEL</button>
11-
</Link>
9+
<Link to={`/${id}`}>{text}</Link>
10+
<button onClick={onBtnClick}>DEL</button>
1211
</li>
1312
);
1413
}

src/store.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createStore } from "redux";
2-
2+
import { createAction } from "@reduxjs/toolkit";
3+
/*
34
const ADD = "ADD";
45
const DELETE = "DELETE";
56
@@ -16,13 +17,16 @@ const deleteToDo = id => {
1617
id: parseInt(id)
1718
};
1819
};
20+
*/
21+
const addToDo = createAction("ADD");
22+
const deleteToDo = createAction("DELETE");
1923

2024
const reducer = (state = [], action) => {
2125
switch (action.type) {
22-
case ADD:
23-
return [{ text: action.text, id: Date.now() }, ...state];
24-
case DELETE:
25-
return state.filter(toDo => toDo.id !== action.id);
26+
case addToDo.type:
27+
return [{ text: action.payload, id: Date.now() }, ...state];
28+
case deleteToDo.type:
29+
return state.filter(toDo => toDo.id !== action.payload);
2630
default:
2731
return state;
2832
}

yarn.lock

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,16 @@
13091309
resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-1.1.3.tgz#2b5a3ab3f918cca48a8c754c08168e3f03eba61b"
13101310
integrity sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw==
13111311

1312+
"@reduxjs/toolkit@^1.4.0":
1313+
version "1.4.0"
1314+
resolved "https://registry.yarnpkg.com/@reduxjs/toolkit/-/toolkit-1.4.0.tgz#ee2e2384cc3d1d76780d844b9c2da3580d32710d"
1315+
integrity sha512-hkxQwVx4BNVRsYdxjNF6cAseRmtrkpSlcgJRr3kLUcHPIAMZAmMJkXmHh/eUEGTMqPzsYpJLM7NN2w9fxQDuGw==
1316+
dependencies:
1317+
immer "^7.0.3"
1318+
redux "^4.0.0"
1319+
redux-thunk "^2.3.0"
1320+
reselect "^4.0.0"
1321+
13121322
"@sheerun/mutationobserver-shim@^0.3.2":
13131323
version "0.3.3"
13141324
resolved "https://registry.yarnpkg.com/@sheerun/mutationobserver-shim/-/mutationobserver-shim-0.3.3.tgz#5405ee8e444ed212db44e79351f0c70a582aae25"
@@ -5246,6 +5256,11 @@ immer@1.10.0:
52465256
resolved "https://registry.yarnpkg.com/immer/-/immer-1.10.0.tgz#bad67605ba9c810275d91e1c2a47d4582e98286d"
52475257
integrity sha512-O3sR1/opvCDGLEVcvrGTMtLac8GJ5IwZC4puPrLuRj3l7ICKvkmA0vGuU9OW8mV9WIBRnaxp5GJh9IEAaNOoYg==
52485258

5259+
immer@^7.0.3:
5260+
version "7.0.8"
5261+
resolved "https://registry.yarnpkg.com/immer/-/immer-7.0.8.tgz#41dcbc5669a76500d017bef3ad0d03ce0a1d7c1e"
5262+
integrity sha512-XnpIN8PXBBaOD43U8Z17qg6RQiKQYGDGGCIbz1ixmLGwBkSWwmrmx5X7d+hTtXDM8ur7m5OdLE0PiO+y5RB3pw==
5263+
52495264
import-cwd@^2.0.0:
52505265
version "2.1.0"
52515266
resolved "https://registry.yarnpkg.com/import-cwd/-/import-cwd-2.1.0.tgz#aa6cf36e722761285cb371ec6519f53e2435b0a9"
@@ -8848,7 +8863,12 @@ redent@^3.0.0:
88488863
indent-string "^4.0.0"
88498864
strip-indent "^3.0.0"
88508865

8851-
redux@^4.0.5:
8866+
redux-thunk@^2.3.0:
8867+
version "2.3.0"
8868+
resolved "https://registry.yarnpkg.com/redux-thunk/-/redux-thunk-2.3.0.tgz#51c2c19a185ed5187aaa9a2d08b666d0d6467622"
8869+
integrity sha512-km6dclyFnmcvxhAcrQV2AkZmPQjzPDjgVlQtR0EQjxZPyJ0BnMf3in1ryuR8A2qU0HldVRfxYXbFSKlI3N7Slw==
8870+
8871+
redux@^4.0.0, redux@^4.0.5:
88528872
version "4.0.5"
88538873
resolved "https://registry.yarnpkg.com/redux/-/redux-4.0.5.tgz#4db5de5816e17891de8a80c424232d06f051d93f"
88548874
integrity sha512-VSz1uMAH24DM6MF72vcojpYPtrTUu3ByVWfPL1nPfVRb5mZVTve5GnNCUV53QM/BZ66xfWrm0CTWoM+Xlz8V1w==
@@ -9029,6 +9049,11 @@ requires-port@^1.0.0:
90299049
resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"
90309050
integrity sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=
90319051

9052+
reselect@^4.0.0:
9053+
version "4.0.0"
9054+
resolved "https://registry.yarnpkg.com/reselect/-/reselect-4.0.0.tgz#f2529830e5d3d0e021408b246a206ef4ea4437f7"
9055+
integrity sha512-qUgANli03jjAyGlnbYVAV5vvnOmJnODyABz51RdBN7M4WaVu8mecZWgyQNkG8Yqe3KRGRt0l4K4B3XVEULC4CA==
9056+
90329057
resolve-cwd@^2.0.0:
90339058
version "2.0.0"
90349059
resolved "https://registry.yarnpkg.com/resolve-cwd/-/resolve-cwd-2.0.0.tgz#00a9f7387556e27038eae232caa372a6a59b665a"

0 commit comments

Comments
 (0)