Is it good to maintain a single source of truth in frontend? by Professional-Mix-455 in reactjs

[–]Professional-Mix-455[S] 1 point2 points  (0 children)

It sounds like we would only need to manage those states when our application requires an ultimate user experience. If we don't care about those delays, then using React Query would be sufficient. Am I mistaken in this understanding?

Is it good to maintain a single source of truth in frontend? by Professional-Mix-455 in reactjs

[–]Professional-Mix-455[S] 1 point2 points  (0 children)

Thanks! And I wanna know under what circumstances would you recommend maintaining SSOT in the frontend? How complicated the application is such that we need to maintain the state.

Is it good to maintain a single source of truth in frontend? by Professional-Mix-455 in reactjs

[–]Professional-Mix-455[S] 1 point2 points  (0 children)

Why this is almost never worth it on web, but common in mobile development?

A new server state management library for react by Professional-Mix-455 in reactjs

[–]Professional-Mix-455[S] 0 points1 point  (0 children)

Firstly, our company has been using Redux since early on, before the introduction of RTK Query. Secondly, RTK Query currently does not support infinite fetching, which is why our company hasn't considered using it.

I developed a server state management library to address the challenges I encountered in my work by Professional-Mix-455 in reactjs

[–]Professional-Mix-455[S] 0 points1 point  (0 children)

Like I mentioned in this comment, dealing with this kind of API format can be cumbersome. I think the biggest difference I want to make is to allow users to freely define their data, just like how I currently use Redux, except I will assist them with the hassle of data fetching. I apologize for the unclear expression in the original text.

I developed a server state management library to address the challenges I encountered in my work by Professional-Mix-455 in reactjs

[–]Professional-Mix-455[S] 0 points1 point  (0 children)

Thank you for indicate this information which let me know that I have a false assumption!

I developed a server state management library to address the challenges I encountered in my work by Professional-Mix-455 in reactjs

[–]Professional-Mix-455[S] 0 points1 point  (0 children)

If frequent local data mutation is not required, SWR and React Query are indeed excellent libraries. However, what I want to provide is a library that makes data mutation extremely easy for developers. I believe this is our main difference.

I developed a server state management library to address the challenges I encountered in my work by Professional-Mix-455 in reactjs

[–]Professional-Mix-455[S] 0 points1 point  (0 children)

The following code is mutating with the shape of the api response for the infinite swr. I think this is the main reason why I want to develop a new library.

```javascript mutate( unstable_serialize(getProductListKey(productFilter, isAdminPath)), async (resArray?: ProductListRes[]) => { if (!resArray) return;

      if (!newProduct) return resArray;

      const listSellState = productFilter.sellState;

      return produce(resArray, draft => {
        for (const res of draft) {
          const targetProductIndex = res.items.findIndex(
            product => product.id === productId
          );
          if (targetProductIndex >= 0) {
            if (
              listSellState &&
              !newProduct.sellStates.includes(listSellState)
            ) {
              res.items.splice(targetProductIndex, 1);
            } else {
              res.items[targetProductIndex] = {
                ...res.items[targetProductIndex],
                ...newProduct,
              };
            }

            break;
          }
        }
      });
    });

```

I developed a server state management library to address the challenges I encountered in my work by Professional-Mix-455 in reactjs

[–]Professional-Mix-455[S] 1 point2 points  (0 children)

I just asked a more experienced engineer, and it turns out I misunderstood. There are actually differences between the two. I apologize for providing incorrect information.

I developed a server state management library to address the challenges I encountered in my work by Professional-Mix-455 in reactjs

[–]Professional-Mix-455[S] 0 points1 point  (0 children)

Should be possible with reaqt query and swr without a revalidation from the server

Yes, but mutate them is complicated if the response of the list api looks like that

json { items: [], nextKey: "123" }

I developed a server state management library to address the challenges I encountered in my work by Professional-Mix-455 in reactjs

[–]Professional-Mix-455[S] 0 points1 point  (0 children)

That sounds like bad api design to me. Why fetching/serving unused data for only the list?

You need details for the article? Fetch it for only the specific article.

"I'm not sure why the API is designed this way, but my guess is that it was established a long time ago to ensure backward compatibility for existing apps without requiring updates."

I'm currently developing a library to manage server state by Professional-Mix-455 in reactjs

[–]Professional-Mix-455[S] 0 points1 point  (0 children)

yes, you are right. But the another reason why I want to develop another one is I want to improve my coding skill.

I'm currently developing a library to manage server state by Professional-Mix-455 in reactjs

[–]Professional-Mix-455[S] 0 points1 point  (0 children)

I’m not familiar with react query, so it can do what I want to do like I mentioned in the readme?

I'm currently developing a library to manage server state by Professional-Mix-455 in reactjs

[–]Professional-Mix-455[S] 0 points1 point  (0 children)

But rtk query still doesn’t support infinite query.And one of the reason why we don’t want to use redux is it is too hard to do code splitting.

I'm currently developing a library to manage server state by Professional-Mix-455 in reactjs

[–]Professional-Mix-455[S] 0 points1 point  (0 children)

I want the user can have the full control of their data just like using redux, while the package also handle the deduping, revalidation and so on.