Blog>
Snippets

Refactoring to String Typed Actions

Showcase a before-and-after comparison of refactoring an existing action creator to comply with Redux v5.0.0 string type enforcement.
// Before refactoring to string typed actions
const ADD_TODO = Symbol('ADD_TODO');

function addTodo(text) {
  return {
    type: ADD_TODO,
    text
  };
}
This is the original action creator using a Symbol for the action type, which is incompatible with Redux v5.0.0.
// After refactoring to string typed actions
const ADD_TODO = 'ADD_TODO';

function addTodo(text) {
  return {
    type: ADD_TODO,
    text
  };
}
This is the refactored action creator conforming to Redux v5.0.0, using a string literal for the action type.