Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Challenge: Involve Redux into React | Redux Toolkit
Expert React
course content

Course Content

Expert React

Expert React

1. React Key Concepts
2. React Router
3. Redux Toolkit
4. Formik
5. Jest
6. Next Steps

bookChallenge: Involve Redux into React

Step 4: Involve Redux logic into React app

Focus on involving Redux logic in a React app. Connect React components and the Redux store to enable state management and actions.

Example

Ship Tracker App

Challenge

Form.jsx:

  1. Open the Form.jsx file.
  2. Import the useDispatch hook from the react-redux package. This hook will be used to dispatch actions to the Redux store.
  3. Import the addGoal action from the goalAction.js file. This action is responsible for adding a goal to the Redux store.
  4. Initialize the dispatch variable inside the component by calling the useDispatch hook.
  5. Complete the handleFormSubmit function by dispatching the addGoal action. Use the dispatch function and pass in an object with the goal details: { id: Date.now(), text: goal }. The Date.now() generates a unique ID for each goal.
  6. Reset the form after submission by calling the resetForm function.

GoalList.jsx:

  1. Open the GoalList.jsx file.
  2. Import the useDispatch and useSelector hooks from the react-redux package. These hooks will be used to access the Redux store and dispatch actions.
  3. Import the removeGoal action from the goalAction.js file. This action is responsible for removing a goal from the Redux store.
  4. Initialize the goals variable using the useSelector hook and access the goals state from the Redux store.
  5. Initialize the dispatch variable by calling the useDispatch hook.
  6. Complete the handleRemoveGoal function by dispatching the removeGoal action. Pass in the goal as a parameter.
  7. Finish the logic of rendering the array of goals by mapping over the goals array and rendering each goal.
  8. Display the text of each goal and add a button with an onClick event that calls the handleRemoveGoal function and passes in the respective goal.

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 3. Chapter 12
some-alt