[Redux] Avoid action type naming conflicts

时间:2023-03-09 03:33:17
[Redux] Avoid action type naming conflicts

In redux, the action type is just a normal string type, it is easy to get naming conflicts in large application.

Can use namespace-constants lib to solve the problem: https://npmdaily.com/pkg/namespace-constants

import constants from 'namespace-constants';

module.exports = constants('todos', [
'ADD_TODO',
'REMOVE_TODO',
'TOGGLE_TODO'
]);
// {
// 'ADD_TODO': 'todos:ADD_TODO',
// 'REMOVE_TODO': 'todos:REMOVE_TODO'
// 'TOGGLE_TODO': 'todos:TOGGLE_TODO'
// }