You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: day-20/post.md
+8-8
Original file line number
Diff line number
Diff line change
@@ -34,15 +34,15 @@ What we _want_ is the ability for our users to update the time by clicking on a
34
34
35
35
We already implemented the third step, so we only have two things to do to get this functionality working as we expect.
36
36
37
-
Yesterday, we discussed what actions are, but not really why we are using this thing called actionCreators or what they are.
37
+
Yesterday, we discussed what actions are, but not really why we are using this thing called actionCreators or what they are.
38
38
39
39
As a refresher, an action is a simple object that _must_ include a `type` value. We created a `types.js` file that holds on to action type constants, so we can use these values as the `type` property.
40
40
41
41
```javascript
42
-
xportconstFETCH_NEW_TIME='FETCH_NEW_TIME';
42
+
exportconstFETCH_NEW_TIME='FETCH_NEW_TIME';
43
43
```
44
44
45
-
As a quick review, our actions can be any object value that has the `type` key. We can send data along with our action (conventionally, we'll pass extra data along as the `payload` of an action).
45
+
As a quick review, our actions can be any object value that has the `type` key. We can send data along with our action (conventionally, we'll pass extra data along as the `payload` of an action).
46
46
47
47
```javascript
48
48
{
@@ -51,7 +51,7 @@ As a quick review, our actions can be any object value that has the `type` key.
51
51
}
52
52
```
53
53
54
-
Now we need to _dispatch_ this along our `store`. One way we could do that is by calling the `store.dispatch()` function.
54
+
Now we need to _dispatch_ this along our `store`. One way we could do that is by calling the `store.dispatch()` function.
55
55
56
56
```javascript
57
57
store.dispatch({
@@ -60,7 +60,7 @@ store.dispatch({
60
60
})
61
61
```
62
62
63
-
However, this is pretty poor practice. Rather than dispatch the action directly, we'll use a function to return an action... the function will _create_ the action (hence the name: actionCreator). This provides us with a better testing story (easy to test), reusability, documentation, and encapsulation of logic.
63
+
However, this is pretty poor practice. Rather than dispatch the action directly, we'll use a function to return an action... the function will _create_ the action (hence the name: actionCreator). This provides us with a better testing story (easy to test), reusability, documentation, and encapsulation of logic.
64
64
65
65
Let's create our first `actionCreator` in a file called `redux/actionCreators.js`. We'll export a function who's entire responsibility is to return an appropriate action to dispatch on our store.
Now we can use the actionCreators to call `login` and `logout` just like the `updateTime()` action creator.
206
+
Now we can use the actionCreators to call `login` and `logout` just like the `updateTime()` action creator.
207
207
208
208
Phew! This was another hefty day of Redux code. Today, we completed the circle between data updating and storing data in the global Redux state. In addition, we learned how to extend Redux to use multiple reducers and actions as well as multiple connected components.
0 commit comments