规范化数据 redux 并使用

问题描述

我有以下来自 API 的数据:

const Feed = {
  id: "FeedId",content: "...",comments: [
    {
      id: "commentId",// reply comments
      comments: [{
        id: "commentId",content: "..."
      }]
    }
  ],}

我想规范化 Redux 中使用的数据,如 here 所示。但是我的数据有嵌套的回复评论。我不知道在哪里放置评论回复。我应该使用规范化数据和 normalizr lib 吗?。非常感谢如果您回答并为我解释。抱歉我的英语不好,但我真的很想知道。

// where place comments reply ???
{
  Feeds: {
    byId: {
      "Feed1": {
        id: "Feed1",comments: ["comment1","comment2"],},"Feed2": {
        id: "Feed2",comments: ["comment3","comment4"],allIds: ["Feed1","Feed2"],comments: {
    byId: {
      "comment1": {
        id: "comment1","comment2": {
        id: "comment2","comment3": {
        id: "comment3","comment4": {
        id: "comment4",allIds: ["comment1","comment2","comment3",};

这是我当前用于处理 FeedReducer 中的提要和评论的 init reducer

const initialState = {
  Feed_id_1: {
    id: "Feed_id_1",comments: [
      {
        id: "comment_id_1",comments: [
          { id: "comment_reply_id_1",content: "..." },{ id: "comment_reply_id_2",],{},// ...
};

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)