gpt4 book ai didi

Redux:数据操作是操作还是化简操作的责任?

转载 作者:行者123 更新时间:2023-12-04 17:43:37 25 4
gpt4 key购买 nike

我的 Action 获取一个网址并得到一个json。

我需要将此json转换为对象数组并设置为状态。

我问你:在哪里必须放置业务逻辑以将json转换为对象数组?

必须放置

  • 放入 Action 代码中,以分配具有“即用型”有效载荷
  • 的 Action

    或者

  • 放入reducers代码中,该代码在有效负载中以json形式接收“原始数据”,然后转换为对象数组并置于
  • 状态

    最佳答案

    根据Redux doc

    Actions are payloads of information that send data from your application to your store.

    Actions describe the fact that something happened, but don't specify how the application's state changes in response. This is the job of reducers.



    因此,我将选择选项2:将其放入reducers代码中,该代码将在有效负载中以json形式接收“原始数据”,然后转换为对象数组并置于状态。

    关于Redux:数据操作是操作还是化简操作的责任?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47051021/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com