DEV Community

Xuan
Xuan

Posted on • Updated on

Build a Single Source of Truth by Using Daxus!

I'm excited to introduce Daxus I've developed to the community. In this article, I would like to simply share with everyone the motivation behind creating Daxus.

First of all, Daxus is a server state management package that make developer have full control over their data such that they can build a single source of truth by themselves.

Someone may ask: why don't you just use React Query or SWR?

In my company, we use redux with async thunk to manage the server state and implement single source of truth by ourselves. Take post as example, suppose there are two lists contain the post with the same id. This post share the same reference in the redux. That is, if the user update this post, the two posts will update simultaneously, and we don't need to make an extra request to refetch the whole post lists.

React Query encourages us invalidate the query if we have some data updated, which means that we need to refetch the whole list. However, refetch the two list just because we update a single post seems wasteful. We hope that we don't need to refetch the lists, but the same post in the both list should update also.

That is why I develope Daxus. You can find more details about the motivation in the readme also. Feel free to see it. https://github.com/jason89521/daxus#development-motivation

If you find this project interesting, also welcome to give it a star. It would be a tremendous encouragement to me. At the same time, I also hope that I can persuade my colleagues to adopt Daxus to our codebase. Thanks for your reading!

There is a question that I'm often asked:

Q: Why don't you just use queryClient.setQueryData?
A: In the pratical cases, we have not only two lists of the posts. If we consider update all these lists, it may be a disaster. Someone may ask, how about queryClient.setQueriesData? The answer is that the type is too dynamic. For more information, you can read this article.

If you have any question, I recommend read the motivation first. It provide more detail of why I want to develope Daxus. Thanks for reading!

Top comments (1)

Collapse
 
jason89521 profile image
Xuan

Daxus is still in its early stage. If you find any bugs or have any problems, feel free to open an issue.