Course contentsShow
← React
Lesson 767 of 2,39620. useReducerFree lesson

Naming Action Types: SCREAMING_SNAKE_CASE

Convention for action type constants like 'ADD_TODO' or 'TOGGLE_COMPLETE' for clarity and consistency.

Naming Action Types: SCREAMING_SNAKE_CASE

What you'll learn: Why action type strings follow the SCREAMING_SNAKE_CASE convention and how it improves your reducer code.

The Convention

When you write action types for reducers, the community convention is to use all uppercase letters with underscores separating words. Instead of "addTodo" or "add-todo", you write "ADD_TODO". Instead of "toggleComplete", you write "TOGGLE_COMPLETE".

Why SCREAMING_SNAKE_CASE?

This convention serves several purposes:

Visual distinction: Action types stand out immediately in your code. When scanning through a reducer's switch statement, these uppercase strings are instantly recognizable as constants, not variables or user data.

Convention as communication: It signals "this is an action type constant" to other developers. Just like const tells you a binding won't be reassigned, SCREAMING_SNAKE_CASE tells you this string represents a specific, intentional action in your system.

Avoiding typos: Because action types are plain strings, a typo like "TOGGLE_COMPLET" would silently fail (hitting your default case). The uppercase convention makes them feel more important, encouraging you to define them as constants that your editor can autocomplete.

In Practice

// Action type constants
const ADD_TODO = "ADD_TODO";
const TOGGLE_COMPLETE = "TOGGLE_COMPLETE";
const DELETE_TODO = "DELETE_TODO";

function todosReducer(state: Todo[], action: TodoAction): Todo[] {
  switch (action.type) {
    case ADD_TODO:
      // ...
    case TOGGLE_COMPLETE:
      // ...
    default:
      return state;
  }
}

Notice how ADD_TODO immediately catches your eye compared to lowercase alternatives.

Key Takeaway: Use SCREAMING_SNAKE_CASE for action type strings to make them visually distinct, communicate intent, and maintain consistency with community standards.