代码之家  ›  专栏  ›  技术社区  ›  Alexis Wilke

React Redux示例有一个非纯函数。我以为还原剂必须是纯的?

  •  0
  • Alexis Wilke  · 技术社区  · 6 年前

    have to be pure .

    有一个例子(来自 this page ):

    // redux/actions.js
    import { ADD_TODO } from "./actionTypes";
    
    let nextTodoId = 0;
    export const addTodo = content => ({
      type: ADD_TODO,
      payload: {
        id: ++nextTodoId,
        content
      }
    });
    
    // ... other actions
    

    那是不是意味着我必须忘记我所学到的一切?

    1 回复  |  直到 6 年前
        1
  •  5
  •   TrueWill    6 年前

    在我看来,这是一个动作创造者,而不是减速机。动作创造者不必是纯粹的。

    动作创建者也可以是异步的并且有副作用。

    https://redux.js.org/basics/actions#action-creators