Blog>
Snippets

Action Creators for Course Progression

Provide examples of Redux action creators for user actions such as starting a course, completing a lesson, and taking a quiz.
// Action types
const START_COURSE = 'START_COURSE';
const COMPLETE_LESSON = 'COMPLETE_LESSON';
const TAKE_QUIZ = 'TAKE_QUIZ';

// Action creators
function startCourse(courseId) {
  return {
    type: START_COURSE,
    payload: { courseId }
  };
}

function completeLesson(courseId, lessonId) {
  return {
    type: COMPLETE_LESSON,
    payload: { courseId, lessonId }
  };
}

function takeQuiz(courseId, quizId) {
  return {
    type: TAKE_QUIZ,
    payload: { courseId, quizId }
  };
}

// Example usage:
// dispatch(startCourse('react-redux-course'));
// dispatch(completeLesson('react-redux-course', 'lesson-1'));
// dispatch(takeQuiz('react-redux-course', 'quiz-1'));
This code example defines action creators for managing course progression, including starting a course, completing a lesson, and taking a quiz.