Action Dispatch
We will be associating the setActiveUserID action we made in the last lesson with the onClick handler of our User div. This will dispatch the action on a click. We will implement this functionality in User.js.
We'll cover the following
In the last lesson we made the action creator called setActiveUserID
, which returns the user object based on the id it is given.
Now we must dispatch the action.
Let’s keep moving.
Take a look at the User.js component.
The first line of the return statement is a div with the class name, User:
<div className="User">
This is the right place to set up the click handler. As soon as this div is clicked, we will dispatch the action we just created.
So, here’s the change:
<div className="User" onClick={handleUserClick.bind(null, user)}>
And the handleUserClick function is right here:
Get hands-on with 1400+ tech skills courses.