action-creatorbeginnerconst ADD_TODO = 'ADD_TODO'
function addTodo(text) {
return { type: ADD_TODO, payload: text }
}
// Typo-safe: ADD_TODOO would throw ReferenceErrorConstants make action types refactor-safe and provide a single source of truth for each string value.
Defining action type strings as named constants eliminates typos and enables autocomplete:
const ADD_TODO = 'ADD_TODO'
const REMOVE_TODO = 'REMOVE_TODO'
If you mistype a constant name, JavaScript throws a ReferenceError. If you mistype a raw string, the action silently fails.
Challenge: Define string constants ADD_TODO, REMOVE_TODO, and TOGGLE_TODO, then implement addTodo(text) that returns { type: ADD_TODO, payload: text }.