在Redux createSlice中组织状态

时间:2020-10-12 08:58:19

标签: react-redux logic

我是Redux的新手,必须组织商店来处理 a 客户,所有客户和客户合作伙伴的CRUD。我正在尝试了解使用createSlice的最佳方法...我是否将所有客户和单个客户的关注点分开?还是将它们合并为一个customerSlice?

const initialState = {
    customerData: [],
    customerStatus: 'idle',
    allCustomerData: [],
    allCustomersStatus: 'idle',
    error: null
}

1 个答案:

答案 0 :(得分:0)

我不确定您的特定应用在# A tibble: 32 x 5 # timestamp time_from_event measurement day time_new # <dttm> <dbl> <dbl> <date> <int> # 1 2020-05-13 08:48:18 NA 11.3 2020-05-13 -5 # 2 2020-05-13 08:48:19 NA 11.3 2020-05-13 -4 # 3 2020-05-13 08:48:20 NA 11.3 2020-05-13 -3 # 4 2020-05-13 08:48:21 NA 11.3 2020-05-13 -2 # 5 2020-05-13 08:48:22 NA 11.3 2020-05-13 -1 # 6 2020-05-13 08:48:23 0 11.3 2020-05-13 0 # 7 2020-05-13 08:48:24 NA 11.3 2020-05-13 1 # 8 2020-05-13 08:48:25 NA 11.3 2020-05-13 2 # 9 2020-05-13 08:48:26 NA 11.4 2020-05-13 3 #10 2020-05-13 08:48:27 NA 11.3 2020-05-13 4 # … with 22 more rows customerData之间有什么区别。

allCustomerData只是与当前客户相对应的customerData条目吗?您永远不会希望在两个地方都拥有相同的信息,因此,如果那样的话,您将想要存储allCustomerData之类的东西,并使用选择器根据以下信息从currentCustomerId中选择当前客户的数据: ID。

阅读entities的概念。看来客户是一个实体,您可能也有其他人。

典型的设置是用一个切片来管理客户,其中状态是由客户ID键控的客户对象。 allCustomerData可能是每个客户对象以及statusnameid等旁边存在的属性。